note 112119 added to function.array-key-exists

From: Date: Tue, 07 May 2013 01:59:57 +0000
Subject: note 112119 added to function.array-key-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-194722@lists.php.net to get a copy of this message
Just a follow up to tom at edgedesigns dot org's multidimensional key_exists - despite him stating that it will always return the correct result, it doesn't because the if statement for $needle equals $key wasn't implicit, he was using the 'equal' comparison operator instead of the 'identical' operator. The correct [updated] code is: function multi_array_key_exists( $needle, $haystack ) { foreach ( $haystack as $key => $value ) : if ( $needle === $key ) { return true; } if ( is_array( $value ) ) : if ( multi_array_key_exists( $needle, $value ) === true ) return true; else continue; endif; endforeach; return false; } --Karl. ---- Server IP: 69.147.83.199 Probable Submitter: 150.101.205.12 ---- Manual Page -- http://php.net/manual/en/function.array-key-exists.php Edit -- https://master.php.net/note/edit/112119 Del: integrated -- https://master.php.net/note/delete/112119/integrated Del: useless -- https://master.php.net/note/delete/112119/useless Del: bad code -- https://master.php.net/note/delete/112119/bad+code Del: spam -- https://master.php.net/note/delete/112119/spam Del: non-english -- https://master.php.net/note/delete/112119/non-english Del: in docs -- https://master.php.net/note/delete/112119/in+docs Del: other reasons-- https://master.php.net/note/delete/112119 Reject -- https://master.php.net/note/reject/112119 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194722) next »