PHPが初めてです。簡単な質問:
コーディング :
foreach($group as $b)
{
if($b == 0){
echo "error";
}
else{
echo "true";
}
}
「真」の値 $b が新しい配列に追加されます。
ありがとう。
$arr = array();
foreach($group as $b) {
if ($b == 0) {
echo "error";
} else {
echo "true";
$arr[] = $b;
}
}
を使用するだけarray_push()
です。
array_push($array, "true");
配列を定義します。
データを配列にプッシュします。
例:
$array = new array();
foreach ($group as $b) {
if ($b == 0) {
echo "error";
} else {
echo "true";
array_push($array,$b) //or any value?
}
}
これを使って:
array_push($arr,"true");
また
echo "true";
$arr[] = $b;
array_pushの詳細については、以下をお読みください。
array_pushを使用して、このリンクを確認してください
$a = new array();
array_push($a,"true");
print_r($a);
次の方法で数値配列に追加できます。
$arr = new array("true"); //Create the array & add the values
var_dump($arr); //Print the contents of the array to screen
値を配列にプッシュすることもできます。
$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
インデックスを直接設定して配列に追加することもできます。
$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