Could anyone let me know how can I allow duplicate keys in php array? I have already read all identical posts concerning this questions and it does not answer my question.
In the following example, I want to pass the second 'separator' key without rename it.
$data = [ 'username' => array( 'type' => 'checkbox', 'id' => 'username', 'label' => 'Show Username Field', 'default' => true, ), 'separator' => array( 'type' => 'separator', 'height' => 'thin' ), 'heading' => array( 'type' => 'textarea', 'id' => 'heading', 'label' => 'Heading Text', 'default' => '', ), 'separator' => array( 'type' => 'separator', 'height' => 'thin' ), 'placeholder' => array( 'type' => 'text', 'id' => 'placeholder', 'label' => 'Placeholder Text', 'default' => 'Your name', ), ]; echo '<pre>'; print_r($data); echo '</pre>';
$data['separator']- which value should be returned?typein subarray - why do you need a key then? Use zero-based indexed array.