For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > August 2007 > array push









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author array push
Harris Kosmidhs

2007-08-02, 6:59 pm

Hello. I have a function which stores a ; seperated file in an array
like this

function readdata($filename,$seperator=";") {
$output=array();

if( ! file_exists($filename)) return $output;

$fp=fopen($filename,"r") ;
while(!feof($fp)) {
$tmp=fgets($fp);
if(strpos($tmp,"#",1)<>1) {
$tmpsp=split($seperator,$tmp);
array_push($output,$tmpsp);
}
}
print_r($output);
}

print_r shows:
Array ( [0] => Array ( [0] => Blah Blah[1] => http://xxx [2] => xxxxxx )
[1] => Array ( [0] => Blah2 [1] => http://yyyy [2] => yyyyy) )

Now I want to loop to every element of $output and print every line like
this:
foreach($output as $o) {
print_r($o);
}

But I get a Warning: Invalid argument supplied for foreach().

Any help?

Harris
Harris Kosmidhs

2007-08-02, 6:59 pm

Harris Kosmidhs wrote:
> Hello. I have a function which stores a ; seperated file in an array
> like this
>



Ok this is lame. I'm sorry. I didn't returned the output value from the
function.

Sorry for the post.

Harris
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com