Here is the vardump for my array:
array(4) {
[3]=> array(1)
{
["match"]=> int(33)
}
[2]=> array(1)
{
["match"]=> int(32)
}
[1]=> array(1)
{
["match"]=> int(16)
}
[4]=> array(1)
{
["match"]=> int(3)
}
}
I need to return the indexes 3, 2, 1, and 4 for use in a query. I have no idea how to do this. I need to run the query in a foreach statement:
foreach($arrayName as $key){
//NEED TO RETURN INDEX HERE
}
I've tried to use key($key)
but that returned the word "match" which is the index of one level below where I need.
Any help will be appreciated.
Easy one ;)
$keys = array_keys($arrayName);
foreach($arrayName as $key => $value){
echo($key);
}
Just add the key to the foreach:
foreach($arrayName as $key => $value){
echo $key; //$key is well... the key and $value is the value of the current element in the array :)
}
foreach($arrayName as $key)
The $key
is actually the value in the array. Try:
foreach($arrayName as $key=>$value)