php - How to get only the first instance of an array that is true of a condition -


i'm new php , i'm trying modify wordpress-based learning management theme (called academy on themeforest) able work out lesson in current course user to.

in other words, want run check see lessons user has completed, getting id of first lesson in course hierarchy has not been completed.

here's know:

within loop of single post (in case "course"), how array of current course's lessons:

<?php $lessons_array = themexcourse::sortlessons(themexcourse::$data['course']['lessons']); ?> 

this produces nested array:

array ( [0] => wp_post object ([id] => 117 [menu_order]=>1) [1] => wp_post object ([id] => 124 [menu_order]=>2) [2] => wp_post object ([id] => 156 [menu_order]=>3)) 

i've truncated bit since 2 values, [id] , [menu_order], important: tell id of each lesson , hierarchy in course.

but stuck: don't want of lesson ids, 1 user has yet complete.

in order check if user has completed lesson or not, i've been using this:

<?php if(themexcourse::iscompletedlesson($lesson_id)) { echo 'completed'; } ?> 

so using above information, possible return single id of next incomplete lesson?

thanks in advance help!

i think should it:

$next_lesson = null; foreach($lessons_array $index=>$lesson) {    if(!themexcourse::iscompletedlesson($lesson->id)) {        $next_lesson = $lesson;        break;    } }  echo "next lesson is: " . $next_lesson->id; 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -