Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert value in array PHP

Tags:

arrays

php

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.

like image 436
Qusyaire Ezwan Avatar asked Dec 13 '22 00:12

Qusyaire Ezwan


1 Answers

$arr = array();
foreach($group as $b) {
    if ($b == 0) {
        echo "error";
    } else {
        echo "true";
        $arr[] = $b;
    }
}
like image 64
Nir Alfasi Avatar answered Dec 23 '22 12:12

Nir Alfasi