I have an array:
Array (
[0] => Array (
[userid] => 5
[0] => 5
[firstname] => DALPA
[1] => DALPA
[lastname] => DALPA
[2] => DALPA
)
)
when i try to print this using foreach loop i get an error
<?php
include('../conn.php');
$q = $_GET['q'];
$adress = $conn->prepare("SELECT * FROM user WHERE firstname= :q ");
$adress->bindValue(':q', $q, PDO::PARAM_STR);
$adress->execute();
$result = $adress->fetchAll();
foreach($result as $item){
echo $item . "\n";
}
?>
Error:Array to string conversion in C:\xampp\htdocs\admin\adres\adres.php on line 13
Been asked many times but none of them solved my problem, what should I do?
My Answer:
"apple",
[1] = "banana",
[2] = "cherry"
);
// Printing the array
foreach ($array as $value) {
echo $value . "
";
}
Rate this post
5 of 5 based on 2387 votesComments