5
<?php       
 $player[] = array();
    $team_id = $_SESSION['tid'];

    $team_pids = $con->prepare("SELECT p_id FROM players_to_team WHERE t_id = ?");

    $team_pids->bindParam(1,$team_id);

    $team_pids->execute();

    while($info = $team_pids->fetch(PDO::FETCH_ASSOC))
    {
            $player[] = $info['p_id'];
            echo $info['p_id'];
    }
    $pl_1 = $player[0];
    .
        .
        .
    $pl_10 = $player[9];

    echo $player[0]; //notice here
    echo $pl_1;      //notice here
?>
<table>

$query = $con->prepare("SELECT role,name,value FROM players WHERE p_id = '".$pl_1."'");
// notice here
               $query->execute();

               while($result = $query->fetch(PDO::FETCH_ASSOC))
               {
                     echo "<tr>";  
                     echo "<td>".$result['role']."</td>";
                     echo "<td>".$result['name']."</td>";
                     echo "<td>".$result['value']."</td>";
            }
?>
</tr>
</table>

when i echo $info array it works fine, but when i echo $player array or $pl_1 variable or $result array values Notice appears...Array to string conversion and o/p doesn't show. why?

HungryDB
  • 555
  • 3
  • 11
  • 30
  • 1
    because both are arrays not a string.Instead of `echo` use print_r($player[0]); and print_r($pl_1); to see the array. – 웃웃웃웃웃 Oct 24 '13 at 11:50
  • you can use [var_dump](http://php.net/var_dump) on any variable to see the variable TYPE as well as it's content to get a better understand of your variable assignments through your code. – Latheesan Oct 24 '13 at 11:53
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – naththedeveloper Oct 24 '13 at 12:01

2 Answers2

11

Try replacing $player[] = array(); by $player = array(); at the beginning (line 2).

This is because that you declare an array at the index 0 of this variable which is told to be an array because of the []. You therefore try to place an array in your array, making it multidimensional.

Guillaume Chevalier
  • 9,613
  • 8
  • 51
  • 79
9

You cannot simply echo an array. echo can only output strings. echo 'foo' is simple, it's outputting a string. What is echo supposed to do exactly in the case of echo array('foo' => 'bar')? In order for echo to output anything here, PHP will convert array('foo' => 'bar') to a string, which is always the string "Array". And because PHP knows this is probably not what you want, it notifies you about it.

The problem is you're trying to treat an array like a string. Fix that.

deceze
  • 510,633
  • 85
  • 743
  • 889