arrays - Using foreach() and php form and custom fucntion -
arrays - Using foreach() and php form and custom fucntion -
i have function returns items have been inputted, works well. in input class:
public static function get($item){ if(isset($_post[$item])){ homecoming $_post[$item]; } else if(isset($_get[$item])){ homecoming $_get[$item]; } homecoming ''; }
now trying utilize in foreach
loop , having problem - think because not returning array?
here form snippet:
<tr> <td><input type="text" class="form-control" name="inventory_item_id[]"></td> <td><input type="text" class="form-control" name="inventory_record_amount[]"></td> <td><input type="text" class="form-control" name="inventory_record_orders[]"></td> <td><input type="text" class="form-control" name="inventory_record_sales[]"></td> </tr>
now when following:
$invitems = input::get('inventory_item_id'); foreach($invitems $a => $b) { //some code here }
phpstorm yells @ me saying:
invalid argument supplied foreach(). expected types: array or object, actual: string.
any ideas wrong?
probably happens when come in first time in page. that's because in first request don't have parameter utilize , don't load page post request, don't have array yet.
to avoid error cant validate if $invitems
array.
$invitems = input::get('inventory_item_id'); if (is_array($invitems)){ foreach($invitems $a => $b) { //some code here } }
php arrays foreach
Comments
Post a Comment