Jump to content

question: array val -> session -> refresh, echo "something", repeat - foreach


DamienRoche

Recommended Posts

Not sure if I was specific enough up there.

 

Here's what I want to do:

 

I have an array with some values, let's say.....

$arr = array('val1','val2','val3');

 

I want to first save those arrays to a session.....

$_SESSION['arr']= $arr;

 

Then I want to refresh.........

header("location:".basename(__FILE__));

 

Then I want to echo then remove one of the values....

echo $arr[0]." has been processed"; 
$arr = array_diff($arr, $arr[0]);

 

Then I want to repeat until there are no more arrays...

 

I would greatly appreciate any insight into how I can achieve this or if it is even possible. I'd like to put it into a foreach somehow...so the updated array is echoed each time but still redirected...agh, I'm confused.

 

 

 

Heres the code, the second file used here is calles test.php through which we pass the value and u can retrieve that value using GET method. 

 

<?php session_start();

$arr = array("one","two");
$_SESSION['arr'] = $arr;

//count the number of items in the array;

$tot = count($arr);
$i = 0;
while($i<$tot){

//lets send the array value to the next page for futher manipulation
$url = "test.php?arrVal=".$_SESSION['arr'][$i];
header('Location: '.$url);
    $i++;
    if($i == $tot){
echo "Completed";
exit;	 	
}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.