Jump to content

echo specific elements from array


dflow

Recommended Posts

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'

-------------->

Link to comment
https://forums.phpfreaks.com/topic/158028-echo-specific-elements-from-array/
Share on other sites

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

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

 

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

 

 

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.