I want to foreach explode from POST multiple values
Cut off "1234" with first space (by character not position)
I get error "Array to string conversion"
Form
<input type="checkbox" name="docid[]" value="1234 harry potter">
Submit
$docID = $_POST['docid'];
foreach($docID as $val) {
echo explode(' ', $val);
}
Output
1234
EDIT
I want to insert output to DB
>Solution :
explode returns an array of strings, so echo won’t work. It also has a third parameter, use that to limit the elements returned:
<?php
$docID = $_POST['docid'];
foreach($docID as $val) {
$exploded = explode(' ', $val, 2);
// print_r($exploded); # Array ( [0] => 1234 [1] => harry potter )
echo $exploded[0];
}
will output 1234
Edit: if you want to cut off 1234 from your result use echo $exploded[1]; – this will output harry potter