hello i’m running into a problem, it says on the browser illegal offset type,
im declaring an array this way:
$matriculas = [
1 => ["99-99-99", "D"],
2 => ["88-88-88", "D"],
];
and the error is in this line :
$series[$option] = [$option['matricula'],$option['type']];
the function looks like this:
<?php
$query ="SELECT * FROM matriculas";
$result = $con->query($query);
if($result->num_rows> 0){
$options= mysqli_fetch_all($result, MYSQLI_ASSOC);
}
$series = array();
foreach ($options as $option) {
$series[$option] = [$option['matricula'],$option['type']];
}
?>
<select name="id">
<option>Select matricula</option>
<?php
foreach ($series as $ID => $values) {
?>
<option name=<?php $ID ?> > <?php echo $values[0]; ?></option>
<?php
}
>
</select>
how can i make it right? thanks in advance for your help
>Solution :
It’s almost right.
Based on the subsequent foreach ($series as $ID => $values), I think you want this instead:
foreach ($options as $option) {
$series[$option['id']] = [$option['matricula'], $option['type']];
}
But unless you’re going to use the $option['type'] value for something else later, it could be simplified to
foreach ($options as $option) {
$series[$option['id']] = $option['matricula'];
}