Default array values if key doesn't exist?
If I have an array full of information, is there any way I can a default for values to be returned if the key doesn't exist? function items() { return array( 'one' => array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, ), 'two' => array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, ), 'three' => array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, ), ); } And in my code $items = items(); echo $items['one']['a']; // 1 But can I have a default value to be returned if I give a key that doesn't exist like, $items = items(); echo $items['four']['a']; // DOESN'T EXIST RETURN DEFAULT OF 99
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.