• Resolved Uriahs Victor

    (@uriahs-victor)


    This is a bit embarrassing but arrays have always given me a run for my money.

    I’m creating a plugin where I will give the user the option to select the interval they want a certain feature within my plugin to run.

    So I’m pulling all cron schedules currently defined using: wp_get_schedules();


    https://codex.www.ads-software.com/Function_Reference/wp_get_schedules

    Then i’m doing this:

    $active_cron_schedules = wp_get_schedules();
    
              print_r(Array_values($active_cron_schedules));
    
              foreach ($active_cron_schedules as $key => $value) {
                echo $key;
              }

    currently it outputs the hourly twicedaily daily my_cron it’s not going deep enough, I want to get the “display” so it shows the “nice name” of the schedule.

    Help is appreciated, thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    This ought to do it: echo $value['display'];
    If you tried to var_dump( $value ); instead of echo $key; you probably would have known what to do. Don’t feel bad, complex arrays are surprisingly difficult to navigate. I’ve had to resort to stepping through each level one by one, using var_dump() each time, in order to get the correct variable reference. Especially with structures that mix associative and indexed arrays, with objects mixed in too. Would you believe I once ended up with something like this:
    $result[2]->data['current'][0]->value ? ??

    When you use print_r() or var_dump(), it helps to have the output go inside a <pre> </pre> block, or view the results in your browser’s source view so the output’s structure is apparent. I often prefer var_dump() because it includes the data type in the output, but print_r() is useful too because the output is cleaner.

    Thread Starter Uriahs Victor

    (@uriahs-victor)

    Thanks alot @bcworkz, it worked. Arrays :3 I need to go to an array bootcamp. Always had a problem fully understanding them.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pull out values from multidimensional associative array’ is closed to new replies.