dflow Posted May 13, 2009 Share Posted May 13, 2009 how do i echo all the elements with [0]? <?php $file = fopen("getCalendar.csv", "r"); while(! feof($file)) { print_r(fgetcsv($file)); } fclose($file); ?> the file generated is like this: <------------------ Array ( [0] => id=5: ) Array ( [0] => id=8:'13/05/2009' [1] => '14/05/2009' [2] => '15/05/2009' [3] => '21/05/2009' --------------> Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/ Share on other sites More sharing options...
hchsk Posted May 13, 2009 Share Posted May 13, 2009 i dont understand what the problem is. if its generateing that file, it is echoing them. no? Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833609 Share on other sites More sharing options...
dflow Posted May 13, 2009 Author Share Posted May 13, 2009 i dont understand what the problem is. if its generateing that file, it is echoing them. no? sorry i missed some text i want to echo all the elements with [0] as key <?foreach($myArray as $key[0] => $value){ echo "$key=.$value"} ? Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833612 Share on other sites More sharing options...
dflow Posted May 13, 2009 Author Share Posted May 13, 2009 what am i doing wrong here? i want to get all the keys[0] and their=> value <?php $file = fopen("getCalendar.asp", "r"); while(! feof($file)) { $myArray[] = fgetcsv($file); } $tmp = array(); foreach($myArray as $key => $value){ $tmp[] = value; } print_r($tmp); ?> what i get is Array ( [0] => value [1] => value [2] => value [3] => value [4] etc Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833643 Share on other sites More sharing options...
jackpf Posted May 13, 2009 Share Posted May 13, 2009 So...what's actually the problem? And that foreach loop is unnecessary as you're essentially just repeating the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833651 Share on other sites More sharing options...
dflow Posted May 13, 2009 Author Share Posted May 13, 2009 So...what's actually the problem? And that foreach loop is unnecessary as you're essentially just repeating the while loop. the problem is that i dont get the result this the result i get when i call the file Array ( [0] => id=5: ) Array ( [0] => id=8:'14/05/2009' [1] => '15/05/2009' [2] => etc i want to get the values of all [0] => so the result will be 5 8 Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833657 Share on other sites More sharing options...
jackpf Posted May 13, 2009 Share Posted May 13, 2009 Idk what you're trying to do, but is this it? <pre><?php $file = fopen("index.php", "r"); while(!feof($file)) { $myArray[] = fgetcsv($file); } print_r($myArray); ?> Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833662 Share on other sites More sharing options...
dflow Posted May 14, 2009 Author Share Posted May 14, 2009 Idk what you're trying to do, but is this it? <pre><?php $file = fopen("index.php", "r"); while(!feof($file)) { $myArray[] = fgetcsv($file); } print_r($myArray); ?> ok with this i get the csv file as and array tree now i want to get the values of elements with a [0\ here is part of the generated source Array ( [0] => Array ( [0] => id=5: ) [1] => Array ( [0] => id=8:'14/05/2009' [1] => '15/05/2009' [2] => i want to get the value without the rest of the data so extract Array ( [0] => id=8:'14/05/2009' to Array ( [0] => id=8: and then echo a list with the values 5 8 etc Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833678 Share on other sites More sharing options...
jackpf Posted May 14, 2009 Share Posted May 14, 2009 You mean like foreach($myArray as $key => $value) { echo $value[0].'<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833682 Share on other sites More sharing options...
dflow Posted May 14, 2009 Author Share Posted May 14, 2009 yes but the reuslt is like this: id=8:'14/05/2009' so i need to foreach explode? or spilt str? i need the 8 Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833688 Share on other sites More sharing options...
jackpf Posted May 14, 2009 Share Posted May 14, 2009 Have a look at preg_split() Quote Link to comment https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/#findComment-833942 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.