-
-
Save Mario-Duarte/d9de8b9338331feeac17b07b9766e27f to your computer and use it in GitHub Desktop.
Revisions
-
Kyle Brumm revised this gist
Nov 11, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <?php /** * Check if an array is a multidimensional array. * * @param array $arr The array to check * @return boolean Whether the the array is a multidimensional array or not @@ -11,7 +11,7 @@ function is_multi_array( $x ) { } /** * Convert an object to an array. * * @param array $object The object to convert * @return array The converted array @@ -22,7 +22,7 @@ function object_to_array( $object ) { } /** * Check if a value exists in the array/object. * * @param mixed $needle The value that you are searching for * @param mixed $haystack The array/object to search -
Kyle Brumm revised this gist
Sep 15, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,26 +11,26 @@ function is_multi_array( $x ) { } /** * Convert an object to an array * * @param array $object The object to convert * @return array The converted array */ function object_to_array( $object ) { if( !is_object( $object ) && !is_array( $object ) ) return $object; return array_map( 'object_to_array', (array) $object ); } /** * Check if a value exists in the array/object * * @param mixed $needle The value that you are searching for * @param mixed $haystack The array/object to search * @param boolean $strict Whether to use strict search or not * @return boolean Whether the value was found or not */ function search_for_value( $needle, $haystack, $strict=true ) { $haystack = object_to_array( $haystack ); if( is_array( $haystack ) ) { if( is_multi_array( $haystack ) ) { // Multidimensional array -
Kyle Brumm revised this gist
Sep 15, 2015 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,26 @@ <?php /** * Check if an array is a multidimensional array * * @param array $arr The array to check * @return boolean Whether the the array is a multidimensional array or not */ function is_multi_array( $x ) { if( count( array_filter( $x,'is_array' ) ) > 0 ) return true; return false; } /** * Check if an array is a multidimensional array * * @param array $object The object to convert * @return array The converted array */ function objToArr( $object ) { if( !is_object( $object ) && !is_array( $object ) ) return $object; return array_map('objToArr', (array) $object); } /** * Check if a value exists in an array/object * -
Kyle Brumm revised this gist
Sep 15, 2015 . 2 changed files with 40 additions and 30 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ <?php /** * Check if a value exists in an array/object * * @param mixed $needle The value that you are searching for * @param mixed $haystack The array/object to search * @param boolean $strict Whether to use strict search or not * @return boolean Whether the value was found or not */ function search_for_value( $needle, $haystack, $strict=true ) { $haystack = objToArr( $haystack ); if( is_array( $haystack ) ) { if( is_multi_array( $haystack ) ) { // Multidimensional array foreach( $haystack as $subhaystack ) { if( search_for_value( $needle, $subhaystack, $strict ) ) { return true; } } } elseif( array_keys( $haystack ) !== range( 0, count( $haystack ) - 1 ) ) { // Associative array foreach( $haystack as $key => $val ) { if( $needle == $val && !$strict ) { return true; } elseif( $needle === $val && $strict ) { return true; } } return false; } else { // Normal array if( $needle == $haystack && !$strict ) { return true; } elseif( $needle === $haystack && $strict ) { return true; } } } return false; } -
Kyle Brumm revised this gist
Sep 15, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ function in_any_array( $needle, $haystack, $strict=false ) { if( count( $haystack ) != count( $haystack, 1 ) ) { foreach( $haystack as $subhaystack ) { if( in_any_array( $needle, $subhaystack, $strict ) ) { return true; } } -
Kyle Brumm revised this gist
Aug 30, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php /** * Check if a value exists in any type of array * -
Kyle Brumm revised this gist
Aug 11, 2015 . No changes.There are no files selected for viewing
-
Kyle Brumm renamed this gist
Aug 11, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Kyle Brumm revised this gist
Aug 11, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ /** * Check if a value exists in any type of array * * @param mixed $needle The value that you are searching for * @param array $haystack The array to search * @param boolean $strict Whether to use strict search or not * @return boolean Whether the value was found or not */ function in_any_array( $needle, $haystack, $strict=false ) { if( count( $haystack ) != count( $haystack, 1 ) ) { foreach( $haystack as $subhaystack ) { if( in_multi_array( $needle, $subhaystack, $strict ) ) { -
Kyle Brumm revised this gist
Aug 11, 2015 . 1 changed file with 18 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,29 @@ /** * Check if a value exists in a multidimensional array * * @param mixed $needle The value that you are searching for * @param array $haystack The array/multidimensional array to search * @param boolean $strict Whether to use strict search or not * @return boolean Whether the value was found or not */ function in_multi_array( $needle, $haystack, $strict=false ) { if( count( $haystack ) != count( $haystack, 1 ) ) { foreach( $haystack as $subhaystack ) { if( in_multi_array( $needle, $subhaystack, $strict ) ) { return true; } } } elseif( is_array( $haystack ) ) { if( in_array( $needle, $haystack, $strict ) ) { return true; } } else { if( $needle == $haystack && !$strict ) { return true; } elseif( $needle === $haystack && $strict ) { return true; } } return false; } -
Kyle Brumm revised this gist
Jul 6, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,9 +6,9 @@ * @param boolean $strict Whether to use strict search or not * @return boolean Whether the value was found or not */ function in_multi_array( $needle, $haystack, $strict=false ) { foreach( $haystack as $subhaystack ) { if( in_array( $needle, $subhaystack, $strict ) ) return true; } -
Kyle Brumm revised this gist
Mar 12, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,5 +11,6 @@ function in_multi_array($needle, $haystack, $strict=false) { if(in_array($needle, $subhaystack, $strict)) return true; } return false; } -
Kyle Brumm revised this gist
Mar 12, 2015 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,10 @@ /** * Check if a value exists in a multi-dimensional array * * @param mixed $needle The value that you are searching for * @param array $haystack The multi-dimensional array to search * @param boolean $strict Whether to use strict search or not * @return boolean Whether the value was found or not */ function in_multi_array($needle, $haystack, $strict=false) { foreach ($haystack as $subhaystack) { -
Kyle Brumm revised this gist
Mar 12, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /** * Check if a value exists in a multi-dimensional array * @param mixed $needle The value that you are searching for * @param array $haystack The multi-dimensional array to search * @param boolean $strict Whether to use strict search or not -
Kyle Brumm created this gist
Mar 12, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ /** * Check if a value is in a multi-dimensional array * @param mixed $needle The value that you are searching for * @param array $haystack The multi-dimensional array to search * @param boolean $strict Whether to use strict search or not * @return boolean Whether the value was found or not */ function in_multi_array($needle, $haystack, $strict=false) { foreach ($haystack as $subhaystack) { if(in_array($needle, $subhaystack, $strict)) return true; } return false; }