r-it Posted April 11, 2008 Share Posted April 11, 2008 Hi there, i would like to know which is the best way of accessing php arrays is: example: for($i = 0; i<= 10; $i++) { echo $val['value'.$i]; } would this work?? Link to comment https://forums.phpfreaks.com/topic/100644-dynamic-array-access/ Share on other sites More sharing options...
obsidian Posted April 11, 2008 Share Posted April 11, 2008 We have no idea how the array was generated or what the keys of the array are. You would probably be best served to simply use a foreach loop: <?php foreach ($val as $k => $v) { echo "Key: $k => Val: $v<br />\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/100644-dynamic-array-access/#findComment-514728 Share on other sites More sharing options...
r-it Posted April 11, 2008 Author Share Posted April 11, 2008 the array is coming from javascript, i had to make my own POST message. all that will be different in the array is the number at the end, are you saying that the way i am gonna do it will not work? Link to comment https://forums.phpfreaks.com/topic/100644-dynamic-array-access/#findComment-514729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.