I’m trying to get the values of an array outside the foreach loop but it’s giving me only one value not all three; the code is like this :
$user_id_worker = array();
foreach ($query_result_worker as $row){
$user_id_worker= $row['user_id'];
var_dump($user_id_worker);
}
var_dump($user_id_worker);
the first var dump gives me:
string '12747' (length=5)
string '12596' (length=5)
string '12759' (length=5)
the second one ( outside the loop ) gives me :
string '12759' (length=5)
any ideas? thanks!
You’re replacing its value instead of adding a value to the array you created.
So the $user_id_worker variable holds only one value. Outside the loop, it’s the last one you put inside (last iteration of the loop).
If you want to add the item to the array inside the loop, do this :