-2

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"
  }
}
2
  • Straight away the issue I see is $_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 Commented May 3, 2018 at 10:20
  • Does this answer your question? How to explode this string into an array like this? Commented Jan 17, 2024 at 16:22

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.