Multiple Array -solved- allways remember to decalre GLOBALS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bogdan
Forum Commoner
Posts: 27
Joined: Wed May 31, 2006 10:07 am
Location: Timisoara, Ro

Multiple Array -solved- allways remember to decalre GLOBALS

Post by bogdan »

Thanks a lot, Bogdan

--------------------------------------------------------

If I have this array:

Code: Select all

$TheMainArray = array(
  "qwerty001" => array(
      "a" => "alfa", 
     .......................),
);
and I know "a". Like this:

Code: Select all

$theVariable = "a";
How do I print "alfa" ?????

Thanks. Bogdan

-------------------------------------------------------------------------------------------------------------------
previous unclear post :
-------------------------------------------------------------------------------------------------------------------
Hi, I am unable to figure the following:
I have an array:

Code: Select all

$zuzu =array(
   "zuzu1" => array (
         "a" => "alfa",
         "b" => "beta",
         ......),
   "zuzu2" => array (
         "asd" => "123",
        .......),
);
I have a form with POST where a user selects options: a,b,.... Which I then look for and am supposed to post to another form, "alfa".....
How do I do that, how do I get the "alfa" from the array?

More code with comments:

Code: Select all

function GetSessionZuzu($SESSION)
{
   $categoryName  = "zuzu";

   if(empty($SESSION[$categoryName]))
      return false;

   $zuzu = $SESSION[$categoryName];

   return $zuzu;
}

// and then :
$ZuzuArray = $session->GetSessionZuzu($SESSION);
if($paramSessionName == 'zuzu')
                              {
                                 $caca = $ZuzuArray[$paramSessionName];
                                 echo "aaaaa : $caca <br>";  // this returns the "a", but I want to return the "alfa" NOT the "a"
                              }


Regards, B
Last edited by bogdan on Thu Jul 13, 2006 9:47 am, edited 4 times in total.
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

I've read it three time's and I still don't know what you are asking. Maybe a rephrase?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Yeah the code you wrote doesn't correlate with your question. If your wanting to know how to retrieve variables from POST data, it's with the $_POST array.

For instance, if you have a form like this...

Code: Select all

<form name="blah" method="POST" action="#">
<input type="text" name="myName" value="" />
</form>
You can retrieve the value of myName when the form is submitted with the code..

Code: Select all

$myName = $_POST['myName'];
echo $myName;
bogdan
Forum Commoner
Posts: 27
Joined: Wed May 31, 2006 10:07 am
Location: Timisoara, Ro

Post by bogdan »

I have a page, on that page I have a form. In that form I have a select. The options in that select are category based.
Category: zuzu, zuzu1, zuzu2, etc.
You can see above I have an array with zuzu(s). Each zuzu is an array also and has elements: a => alfa , etc.

When the user selects an option from the given select box, the thing that he selects is "a".

Now, if he selects "a", I want to look in the array and get the "alfa" value. I seem unable to figure out how to do this.

Code: Select all

$zuzu = array (
     "zuzu" => array(
           "a" => "alfa",
           ..... ),
     "zuzu1" => array(
           "asd" => "123",
           .......),
);
Thank you, B


PS- sorry for being unclear :(
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

It will be in: $ZuzuArray[$paramSessionName][$_POST['nameofyourselect']]

But there are better ways to do what you are trying.
bogdan
Forum Commoner
Posts: 27
Joined: Wed May 31, 2006 10:07 am
Location: Timisoara, Ro

Post by bogdan »

No, that's not it, or I am missunderstanding what you are saying.

$paramSessionName is zuzu.
$ZuzuArray[$paramSessionName] is "a".

If I understabd correctly what you are saying, $_POST['nameofyourselect'] is also "a". User selects an option from the select, what he selects has value="a". Now in that array I have : a=> alfa. I want to get the alfa, to print it, or whatever, anything.
Post Reply