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?

3
  • 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. Commented Oct 24, 2013 at 11:50
  • you can use 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. Commented Oct 24, 2013 at 11:53
  • possible duplicate of Reference - What does this error mean in PHP? Commented Oct 24, 2013 at 12:01

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

One does not simply echo an array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.