Array_combine in foreach loop wont work

How come this code dont really work as I expected when using array_combine ?

$stmt = $oDB->prepare('INSERT INTO customships SET partID=:partID, shipID=:shipID, position=:position');
$partID = array(6, 4, 1, 0, 0);
$position = array('attack', 'defense', 'shield', 'cargo', 'other');

foreach (array_combine($partID, $position) as $x => $y) {
    $stmt->execute(array(':partID' => $x, ':shipID' => $shipID, ':position' => $y));
}

Can you expand on what it does that you weren’t expecting? I’m assuming it’s not inserting the new rows into the database, but does it fail to insert at all, or insert with incorrect values? I assume you set $shipID somewhere else?

It was a typo in there. It works anyway. Sorry

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.