0

i have a html form in which i use array like this (name="courts[]"). when it send data to php file i use foreeach loop to create multidimensional array for inserting records in mysql. In php file i write foreeach loop to iterate like this

    $data = array();
    $i = 0;
    foreach ($court_name as $result)
    {
        $data[] = array(
            'court_name' => $result[0]
        );
        $i++;
    }

it display result this

 Array
 (
      [0] => Array
       (
            [court_name] => P
       )

      [1] => Array
      (
           [court_name] => S
      )

 )

instead of this

 Array
 (
      [0] => Array
       (
            [court_name] => Punjab
       )

      [1] => Array
      (
           [court_name] => Sindh
      )

 )

2 Answers 2

2

(referring the outputs) in your loop, $result contains court name. So if you use $result[0], you get first character of string.

Try this:

foreach ($court_name as $result)
{
    $data[] = array(
        'court_name' => $result
    );
    $i++;
}
Sign up to request clarification or add additional context in comments.

Comments

0

foreach loop gives you one element of array ($result) now you access to the first character of value via $result[0], change it to $result

foreach ($court_name as $result) {
  $data[] = array( 'court_name' => $result );
}

Comments

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.