[RESOLVED] Count Multidimensional Arary Items
I've created an array with the below format.
$UserDetails[0][0]
$UserDetails[1][0]
$UserDetails[2][0]
$UserDetails[0][1]
$UserDetails[1][1]
$UserDetails[2][1]
I need to loop through the array but count($UserDetails) returns 3 which seems incorrect as there are only 2 "items" in the array that contains 3 values each. How can I get the number of "items" (in this case 2)?
EDIT: If it makes a difference I'm declaring $UserDetails as a gloabl array.
PHP Code:
$GLOBALS['UserDetails'] = $UserDetails; //make available in another function
//Then to call it in another function
global $UserDetails;
Re: Count Multidimensional Arary Items
You have the dimensions the wrong way around. It should be:
$UserDetails[0][0]
$UserDetails[0][1]
$UserDetails[0][2]
$UserDetails[0][0]
$UserDetails[0][1]
$UserDetails[0][2]
Re: Count Multidimensional Arary Items
Thanks VisualAd.
Changed my dimensions but now when I attempt to show an item in the array it returns Array[1] or Array[2] etc...?
PHP Code:
global $UserDetails;
$items = count($UserDetails);
echo "items = $items<p>"; //Shows 2 which is correct
echo "Array Item - $UserDetails[1][1]";