0


I am doing one project.In that project i am having some issues in multi arrays.
This (categ[0][category],categ[1][category],categ[2][category]) is dynamic.For refernce I am doing static..Select option is multiple

<select multiple name="categ[0][category]">
          <option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
           </select>
            <select multiple name="categ[1][category]">
          <option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
           </select>
           <select multiple name="categ[2][category]">
          <option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
           </select>

After POST,It shows only last value.(eg.)If I select 2,3,4 in categ[0][category] and 1,3,4 in categ[1][category] and 2,3 in categ[2][category] .It display only 4,4,3 these are selected last values.

this is my php code..

           $categ=array();$categ=$_POST['categ'];
foreach ($categ as $row)
{

    $ddd=array();echo $ddd=$row['category'];
    foreach($ddd as $ds)
    {
   foreach($ds as $fdfd)
   {
       echo implode(",",$fdfd);
   }
    }
}
2
  • Are you getting any error?? Commented Nov 3, 2015 at 10:51
  • No error,that is multiple selection,I am getting only last value in every selection.. Commented Nov 3, 2015 at 10:53

1 Answer 1

1

Remove one foreach in your code

$categ = array();
    $categ = $_POST['categ'];
    foreach ($categ as $row) {

        $ddd = array();
        echo $ddd = $row['category'];
        foreach ($ddd as $ds) {
            echo implode(",", $ds);
        }
    }
Sign up to request clarification or add additional context in comments.

2 Comments

No,now coming only last value,(means third select category last value.in above eg value is 3)..
According to your view, you will get only 1 value coz you have categ[1][category], [2]...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.