0

I have this array:

$array = array(
    "foo" => "bar",
    "barw"    => "21",
    "bara"    => "22",
    "barq"    => "25",
    "multix" => array(
         "1" => array(
             "ar1" => "food",
             "ar2" => "dr",
             "ar3" => "ch",
             "ar4" => "ju"
         ),
        "2" => array(
             "ar1" => "food",
             "ar2" => "dr",
             "ar3" => "ch",
             "ar4" => "ju"
         ),
    "893" => "bar",
    "563" => "bar",
    "hd8" => "bar",
    "multiv" => array(
         "1" => array(
             "ar1" => "food",
             "ar2" => "dr",
             "ar3" => "ch",
             "ar4" => "ju"
         ),
         "2" => array(
             "ar1" => "food",
             "ar2" => "dr",
             "ar3" => "ch",
             "ar4" => "ju"
         ),
    "tw" => "bar",
    "qa" => "bar",
    "op" => "bar"
    )
    )
);

which I am reading from and writing to like this:

echo '<pre>';
print_r($array);
echo '</pre>';

echo "<br/>";
echo $array['multix']['1']['ar1'].'<br/>';
echo "<br/>";
echo $array['multix']['1']['ar2'].'<br/>';
echo "<br/>";
echo $array['multix']['1']['ar3'].'<br/>';
echo "<br/>";
echo $array['multix']['1']['ar4'].'<br/>';
$array['multix']['1']['ar4'] = "lego";

However, I am unable to delete an array of my choice like:

unset($array['multiv']['1']);

echo '<pre>';
print_r($array);
echo '</pre>';

What should I do to delete the array using its key?

1 Answer 1

3

Your multiv array is inside the multix array so you need to prepend the multix name

unset($array['multix']['multiv']['1']);

you may be setting your array wrong if multiv was supposed to be one up in the index level.

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

1 Comment

To expand on this: after ['multix']['2'] ends, you've reduced the indent on ['893'] but the brackets for ['multix'] are still open. Then, at the bottom, you close two sets of brackets at the same level of indent; the second is for ['multix']. Move one of those closing brackets up before ['893'] and you should be good.

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.