pdtest Posted February 21, 2009 Share Posted February 21, 2009 Am trying to use Array in my PHP Script with foreach loop...... foreach ($ratiolist[$index] as $ratio_index=>$ratio_value) { $ratio=$ratio_value->ratio; echo "$ratio"; } This works fine and I get the value of ratio from the array..... Question: I do not want to use foreach loop and hence How can I extract the $ratio_value value ? I tried the following: $ratio=$ratiolist[$index] echo "$ratio"; Results: It says its an Array..... Any Suggestions ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/146229-php-array-help/ Share on other sites More sharing options...
haku Posted February 21, 2009 Share Posted February 21, 2009 If you only want the very first value, then this should work: $ratio=$ratiolist[$index][0]; Quote Link to comment https://forums.phpfreaks.com/topic/146229-php-array-help/#findComment-767704 Share on other sites More sharing options...
pdtest Posted February 21, 2009 Author Share Posted February 21, 2009 No, I do not want the first value.....In fact $index is the variable being passed to this script and hence we are looking for the value in the array for that index.. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/146229-php-array-help/#findComment-767709 Share on other sites More sharing options...
haku Posted February 21, 2009 Share Posted February 21, 2009 If there is more than one value for that index, and you want them all, then you will need to use your foreach loop. If there is only one value for that index, or there is more than one, but you only want the first value, the code I gave you will do it. Quote Link to comment https://forums.phpfreaks.com/topic/146229-php-array-help/#findComment-767721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.