Trying to insert records using a foreach
loop.
$test = array(123, 231, 321, 543);
foreach($test as $key) {
$data = array('name' => 'test_name', test' => $test[$key], 'property' => 'test_property');
Test_table::insert($data);
}
Using a foreach
gives an error Undefined offset: 123
.
Inserting this way works though:
$data = array(
array('name' => 'test_name', test' => 123, 'property' => 'test_property'),
array('name' => 'test_name', test' => 231, 'property' => 'test_property'),
array('name' => 'test_name', test' => 321, 'property' => 'test_property'),
array('name' => 'test_name', test' => 543, 'property' => 'test_property'),
);
Test_table::insert($data);
What is wrong?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2IyOIxR
via IFTTT
Aucun commentaire:
Enregistrer un commentaire