scvinodkumar Posted August 8, 2009 Share Posted August 8, 2009 I have a array like this, Array ( [105] => stdClass Object ( [fullname] => Test [icon] => 89 ) ) I want the value 105 from the above array, how to do get this value? Link to comment https://forums.phpfreaks.com/topic/169325-get-array-value/ Share on other sites More sharing options...
trq Posted August 8, 2009 Share Posted August 8, 2009 $val = $arr[105]; Link to comment https://forums.phpfreaks.com/topic/169325-get-array-value/#findComment-893503 Share on other sites More sharing options...
scvinodkumar Posted August 8, 2009 Author Share Posted August 8, 2009 No, 105 will come dynamically, so it will 106,110,etc Link to comment https://forums.phpfreaks.com/topic/169325-get-array-value/#findComment-893504 Share on other sites More sharing options...
Catfish Posted August 8, 2009 Share Posted August 8, 2009 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 More sharing options...
trq Posted August 8, 2009 Share Posted August 8, 2009 So... you want to loop through all the values in an array? foreach ($arr as $k => $v) { echo "$k = $v\n"; } Link to comment https://forums.phpfreaks.com/topic/169325-get-array-value/#findComment-893512 Share on other sites More sharing options...
scvinodkumar Posted August 8, 2009 Author Share Posted August 8, 2009 yeah i got it thanks to all Link to comment https://forums.phpfreaks.com/topic/169325-get-array-value/#findComment-893513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.