2

I have an multidimensional array made out of form data that can look like this example:

array [
  "absender" => "Maxim Ivan",
  "email" => "[email protected]",
  "telefon" => "1234567890",
  "fax" => null,
  "grund" => "Gehaltserhöhung",
  "termin" => [
     0 => [
       "person" => "Some Name",
       "meeting" => "10.05"  
     ],
     1 => [
       "person" => "Another Name",
       "meeting" => "18.05"  
     ],
     2 => [
       "person" => "Again another name",
       "meeting" => null,
       "next-possible-meeting" => "1"  
     ],
     3 => [
       "person" => "And again",
       "meeting" => null,
       "next-possible-meeting" => "1"  
     ],
      4 => [
        "meeting" => null,
     ],
  "bemerkung" => "some notes by Maxim"
]

'person' and 'next-possible-meeting' are checkboxes while 'meeting' is a textarea. I only need the 'termin'-data when 'person' exists, so I store each of them in different arrays (one for persons, one for meetings and one for next-possible-meetings).

That means I don't need the array to be nested anymore, the 'termin' can (and should) be deleted out of it. But I don't know how to access the nested array correctly.

How do I delete the whole 'termin'-array out of the whole array and therefore make it a normal and not a multidimensional array?

1
  • You mean like this? 3v4l.org/7bHCd Commented May 23, 2019 at 11:31

1 Answer 1

3

Use unset()

if(isset($array['termin'])){
  unset ($array['termin']);
}

Output:- https://3v4l.org/1Yj4F

Note:- isset() used to check that index exist or not, if not function call will saved.

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

2 Comments

Actually unset doesn't flag an undefined index error, it just does nothing. 3v4l.org/abU1j
You're right, I just found out that somehow I made an object (i don't know where in my code that happened) so I just need if(isset($array->hefte)) { unset ($array->hefte);}

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.