codeigniter - How can I use array to schedule post by php? -


$task = array(                 "t2"    => array("10:11","12:00","23:18"),                 "t3"    => array("08:00","11:30"),     ); $post = array("post 1","post 2","post 3","post 4","post 5","post 6","post 7"); 

hi everybody, how can use array schedule post php? have tried use foreach it's not working me :(

i want schedule such as:

post 1: t2 @ 10:11 post 2: t2 @ 12:00 post 3: t2 @ 23:18 post 4: t3 @ 08:00 post 5: t3 @ 11:30 post 6: t2 @ 10:11 post 7: t2 @ 12:00 

.......

please me :)

you need one. first of need make array easy access , flexible, while creating array need store total amount of data, cause post use same data recursively. here create $total variable store total value , check in second foreach loop greater or not if set current looping variable $i 0 again access array first index.

online check

$task = array(             "t2"    => array("10:11","12:00","23:18"),             "t3"    => array("08:00","11:30"),         ); $post = array("post 1","post 2","post 3","post 4","post 5","post 6","post 7");  $arr = array(); $i = 0; foreach($task $k => $t){     foreach($t $tas){         $arr[$i++] = array($k, $tas);     } } $total = $i - 1; $i = 0; foreach($post $val){     if($i > $total)         $i = 0;     echo ucfirst($val).": ".ucfirst($arr[$i][0])." @ ".$arr[$i][1]."\n";     $i++; } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -