Jump to content

Get array value


scvinodkumar

Recommended Posts

for ($i = 0; $i < count($array); $i++)
{
    if (array_key_exists($i, $array))
        // $i is equal to a distinct, existing array key so you can do what you please with that value of $i from there on
}

 

if you do not know the key name of the index you want in an array, then you cannot access the data that is under that key. If your aim is to search for data in the array and return the key name if certain terms are found in the array's data, you could use the loop sequence above to obtain the key, just change the array_key_exists call to something else (something to verify that $i is the key you want).

 

if you are using associative array, you would need to use foreach () not for ().

Link to comment
https://forums.phpfreaks.com/topic/169325-get-array-value/#findComment-893511
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.