SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    933
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    in_array as needle?

    Hi guys,

    I have an array like this,
    Code:
    Array
    (
        [0] => Array
            (
                [lessonid] => 1
                [classid] => 4
            )
    
        [1] => Array
            (
                [lessonid] => 12
                [classid] => 7
            )
    
    )
    I want to search in classid

    I tried,
    Code:
    	$data_current_classes = array();
    	$data_lesson2 = $this->lessons_mdl->get_all_classes();
    	foreach ($data_completion as $row) {
    		if (in_array(array($row['classid']), $data_lesson2)) {
    			echo 'Found: ' .$row['classid']. '<br>';
    		}
    	}

    But fail,

    Thanks in advance.
    Quality codes are optimized and tested...
    Click here for inspiration..

  2. #2
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    933
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    These codes below solved my problem.
    Code:
    function in_array_r($needle, $haystack, $strict = false) {
        foreach ($haystack as $item) {
            if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
                return true;
            }
        }
    
        return false;
    }
    Very cool and very fine and professional codes.
    Thanks to the creator of these codes.

    Awesome!
    Quality codes are optimized and tested...
    Click here for inspiration..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •