Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to send an array from a function to another. This code is not displaying errors on the page but if i go the source code first error says "SCREAM: Error suppression ignored for" and then "Notice: Undefined offset: 0". Since this is the first time im trying to do something like this I cant figure out where is the problem so, hope yo guys can help me.

function Link($db,$url,$pos,$rows_affect){ 

    for(){

       $array[$line]=$url; // when i echo this i get 3 links

       if($pos==$rows_affect-1){  
           $var_dump($array); // here its only showing the last value from the array        
           player($db,$array);
       }

    }

}

function player($db,$array){

    for ($i = 0; $i < count($array); $i++) {

        echo $array[$i];

    }

}
share|improve this question
1  
what is $line? Also, try to do var_dump($array) inside player to see what it actually contains – Matthew Apr 28 at 21:58
As mentioned by Matthew, we need to know what is $line? var_dump will help you solve the problem yourself. – Sumoanand Apr 28 at 22:03
@Matthew $line is the increment from a for cicle. I didnt put it to short the code. Also did var_dump($array) and it only echos the last value from the array. 2 values are missing.. – miguelfsf Apr 28 at 22:05
can you post the message you get from the var_dump statement? From the sounds of it, it seems like you're using an associative array and not a zero-indexed array, in which case Kolink's answer is probably what you want. – Matthew Apr 28 at 22:07
@Matthew This is the result from var_dump "array (size=1) 27 => string 'myurl' (length=219)". My array size should be 3! Kolink answer worked but only echos the last value from the array – miguelfsf Apr 28 at 22:13
show 6 more comments

closed as not a real question by Gordon Apr 29 at 9:24

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

It looks like you have a sparse array.

Try using foreach($array as $i=>$item)

share|improve this answer
worked but its only sending the last value stored on the array. Any tip? – miguelfsf Apr 28 at 22:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.