I am having difficulties in exploding string by "-" and creating a new array.
I get values in an array over checkbox from the HTML table. Values are in the string which needs to be separated by "-" and form new array under array (array example below).
At the end I should get array[0]
[0]=>002251/18
[1]=>1
[2]=>1000
[3]=>5500.00
[4]=>800
I need final output:
if(isset($_POST["submit"])){
$paketi = array();
$prikolica = $_POST["truck"];
$nalozi[] = $_POST["items"];
}
nalozi[] -> OUTPUT
array(1) {
[0]=>
array(3) {
[0]=>
string(28) "002251/18-1-1000-5500.00-800"
[1]=>
string(28) "002251/18-2-1000-5500.00-800"
[2]=>
string(28) "002251/18-3-1000-5500.00-800"
}
}
1 Answer 1
1.You need to iterate over $_POST["items"] first
2.Explode this array each individual value by - and assign this new coming array to your $nalozi array.
foreach($_POST["items"][0] as $items){
$nalozi[] = explode('-',$items);
}
print_r($nalozi);
Output:-https://eval.in/998660
answered May 3, 2018 at 10:22
Death-is-the-real-truth
72.3k10 gold badges59 silver badges106 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-php
$_POST["items"];is an array and you're not looping it (or setting it correctly) to construct your secondary array, you're just dumping the whole contents into the first key