Find current 'numerical' position value of array

Discussion in 'PHP' started by Omzy, Nov 30, 2008.

  1. #1
    I'm trying to find out the current 'numerical' position value of an array. Here is the code I have at the moment:

    
    $menu1 = array('1'=>'Entertainment', '2'=>'Venues', '3'=>'Transport', '4'=>'Catering', '5'=>'Decorations', '6'=>'Essentials');
    
    Code (markup):
    
    foreach ($menu1 as $value1 => $index1)
    {
    	//do something here
    	foreach ($cat as $index => $value)
    	{
    		if ($cat[$index][0] == key($menu1) && $cat[$index][1] == $value1)
    		{
    			//do something here					
    		}
    	}
    }
    
    Code (markup):
    Basically I need the value of $cat[$index][0] to match the current value of the $menu1 array as it is being accessed in the FOR loop. For example in the first cyle, $menu1 should be initialised to '1'=>'Entertainment' and hold the value of 1.
     
    Omzy, Nov 30, 2008 IP
  2. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    At the moment, key($menu1) doesn't seem to be matching up with the assigned values in the $menu1 array
     
    Omzy, Nov 30, 2008 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #3
    It is impossible for me to understand any line of this pointless code, sorry.
     
    wmtips, Nov 30, 2008 IP
  4. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #4
    and.. where is your $cat array...?
    (before call foreach function, you need varible with array type)
     
    misbah, Dec 1, 2008 IP