im new in PHP. just a simple question :
Coding :
foreach($group as $b)
{
if($b == 0){
echo "error";
}
else{
echo "true";
}
}
i want value $b that "true" add to new array.
thanks.
Use it:
array_push($arr,"true");
or
echo "true";
$arr[] = $b;
To know more about array_push read this :
$arr[] instead of array_push() - it's faster.use array_push check this link
$a = new array();
array_push($a,"true");
print_r($a);
We can add to a numerical array in these ways:
$arr = new array("true"); //Create the array & add the values
var_dump($arr); //Print the contents of the array to screen
You can also push values to an array:
$arr = new array(); //Create the array
array_push($arr, 'true'); //'Push' the value into the next available index
var_dump($arr); //Print the contents of the array to screen
You can also add to array by directly setting the index:
$arr = new array(); //Create the array
$arr[0] = 'true'; //'Set' index 0 to the value
var_dump($arr); //Print the contents of the array to screen
foreach