Mu Lem
Mu Lem

Reputation: 71

Explode string then create array

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"
  }
}

Upvotes: -2

Views: 59

Answers (1)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72289

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

Upvotes: 1

Related Questions