0

I am really struggling with arrays in general but I can't seem to do anything with this: https://www.easycron.com/document/list

I want to be able to access each "field". For example the [cron_job_name] for [2]. So in that example the result I'd be looking for is "Send newsletters".

I have been messing around all night long but I think the thing I am not getting past is that it has the [status] => success [cron_jobs] => Array at the top.

So far the code I have is this:

$json = file_get_contents("https://www.easycron.com/rest/list?token=[MY     KEY]&sortby=cronId&order=desc");
$myArray = json_decode($json,true);
echo "<pre>";
print_r($myArray);
echo "</pre>";

All this really does though is gets me a copy of what is on that page.

1
  • 2
    foreach ($myArray['cron_jobs'] as $cron_job) { print_r($cron_job); } -- start with that. Commented Jun 24, 2014 at 0:15

1 Answer 1

1

if you are able to print_r the array response, then you can cycle

if($myArray['status'] ==='success') {
   $crons = $myArray['cron_jobs'];
   foreach($crons as $cron){
     if($cron['cron_job_name'] == 'Send newsletters') {
        // Do your proccessing
        break;
     }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Got it!!! Thank you so much. now I just add a <? echo ($crons[1][url]); ?> for example and it gives me the right value !!! Superstar tanks a lot.
Ok! Remember to put your non numeric keys between ''.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.