1

Im' getting the error:

Strict Standards: Only variables should be passed by reference

This is the code:

foreach (array_unique($meeting) as $entry) {
    if (array_shift(array_values($meeting)) == $entry and $venue ==""  or $venue == $entry) {
        echo '<b><a href="http://mr-tipster.com/pages/racecard.php?venue='.$entry.'">'.$entry.'</a>   </b> ';

        if ($venue =="") {
            $venue = array_shift(array_values($meeting));
        }

    } else {
        echo '<a href="http://mr-tipster.com/pages/racecard.php?venue='.$entry.'">'.$entry.'</a>    ';
    }

}

I have seen other messages on here regarding it, but i cannot seem to solve the error

Rizier123
  • 58,877
  • 16
  • 101
  • 156
emma perkins
  • 749
  • 1
  • 10
  • 28
  • That's not full error message. There was also information about line number. – Elon Than Feb 12 '15 at 12:23
  • sorry errors seem to be on lines with array_shift(array_values($meeting)); – emma perkins Feb 12 '15 at 12:25
  • I might be mistaken but all those conditions + the initial array_unique seem to boil down to: wrap the output for the first item in `...` ....unless $venue has been set earlier (before the loop) to something else than "". – VolkerK Feb 12 '15 at 13:00

3 Answers3

2

This error is because of the array_shift() function. You can't pass

array_values($meeting)

directly to this function you have to save it in a tmp variable for example:

$tmp = array_values($meeting);

And then you can use it like this:

$venue = array_shift($tmp);  //Same for the if statement

For more information about array_shift() see the manual: https://php.net/manual/en/function.array-shift.php

And a quote from there:

mixed array_shift ( array &$array )

As you can see from the manual you have to pass it by reference (Because you can't change the signature of the function) and you can pass these by reference:

  • Variables, i.e. foo($a)
  • New statements, i.e. foo(new foobar())
  • References returned from functions, i.e.:

Passing by Reference

Rizier123
  • 58,877
  • 16
  • 101
  • 156
0

Like you can see in manual (here) array_shift takes reference to the array not actual value.

So you have to assing array_values($meeting) to some variable and the use it with array_shift.

Elon Than
  • 9,603
  • 4
  • 27
  • 37
-1

Try following code

 $meeting = array_unique($meeting);
 foreach ( $meeting as $entry) {
    $meeting = array_values($meeting);
    $meeting = array_shift($meeting);
    if ( $meeting == $entry && $venue ==""  || $venue == $entry)
    {
    echo '<b><a href="http://mr-tipster.com/pages/racecard.php?venue='.$entry.'">'.$entry.'</a>   </b> ';
    if ($venue =="")
    {
    $meeting = array_values($meeting); 
    $venue = array_shift($meeting);
    }
    }
    else
    {
    echo '<a href="http://mr-tipster.com/pages/racecard.php?venue='.$entry.'">'.$entry.'</a>    ';
    }
    }
Elby
  • 1,624
  • 3
  • 23
  • 42