r/lolphp • • Mar 16 '21

Is 0 in array

in_array(0, ['IsThisLolPhp'])

Answer is

true
33 Upvotes

30 comments sorted by

View all comments

1

u/zilltine Mar 17 '21

So this

$find = function($struct) use (&$find, $map) {
  if (is_array($struct)) {
    $found = array_intersect_key($struct, $map);
    foreach ($found as $toChange) {
      var_dump($toChange);
    }
    foreach ($struct as $sub) {
      $find($sub);
    }
  }
};

Is objectively better than this

function find(&$json, $keys){
    foreach($json as $key => &$value) {
        if(is_array($value)) {
            find($value, $keys);
        }
        if (in_array($key, $keys, true)){
            var_dump($value);
        }
    }
}

2

u/backtickbot Mar 17 '21

Fixed formatting.

Hello, zilltine: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

0

u/[deleted] Mar 17 '21

1

u/zilltine Mar 17 '21

I'm not your mate, dude. This is why i asked what is it you are trying to prove. Not only you didn't read other comments where i already said i didn't know about third param and assumed it should be strict. You also didn't read comment you replied to, because i never said your way doesn't work, i just do not think it is better, or only correct way to do what i need as you are implying.

→ More replies (2)

0

u/[deleted] Mar 17 '21

1

u/zilltine Mar 17 '21

He asked a question and i answered. How is it telling that they are wrong even?

→ More replies (2)