meadsy25
01-13-2012, 05:32 PM
I have got a script running where I need to split a string and update parts of it. Would now like to update parts of it depending the value of part of the string.
//$string = "2011-12-13;;1;;0;;3,2011-12-14;;1;;0;;1,2011-12-15;;1;;0;;5,2011-12-16;;1;;0;;1;";
$updatedSets = array();
$updatedString = '';
$sets = explode(',',$string);
foreach($sets as $set) {
$setArray = explode(';;',$set);
//$setArray[2] corresponds to the season
//$setArray[1] corresponds to the price
//echo "<br />".$set;
if($setArray[3] == 1) {
$setArray[2] = $high;
}
array_push($updatedSets,implode(';;',$setArray));
}
$updatedString = implode(',',$updatedSets);
I had managed to get the first 4 characters of $setArray[0] .
It was somthing like this:
$thisyear=$setArray;
echo substr($thisyear,0,4);
But I am not 100% sure how to tie it in with my script so that I can achieve somthing like the following:
if(($setArray[3] == 1)AND($thisyear == 2012)) {
$setArray[2] = 500;
}
So that only sections of the string which have 2012 in them are updated.
Any pointers would be greatly appreciated.
Cheers
Rich
//$string = "2011-12-13;;1;;0;;3,2011-12-14;;1;;0;;1,2011-12-15;;1;;0;;5,2011-12-16;;1;;0;;1;";
$updatedSets = array();
$updatedString = '';
$sets = explode(',',$string);
foreach($sets as $set) {
$setArray = explode(';;',$set);
//$setArray[2] corresponds to the season
//$setArray[1] corresponds to the price
//echo "<br />".$set;
if($setArray[3] == 1) {
$setArray[2] = $high;
}
array_push($updatedSets,implode(';;',$setArray));
}
$updatedString = implode(',',$updatedSets);
I had managed to get the first 4 characters of $setArray[0] .
It was somthing like this:
$thisyear=$setArray;
echo substr($thisyear,0,4);
But I am not 100% sure how to tie it in with my script so that I can achieve somthing like the following:
if(($setArray[3] == 1)AND($thisyear == 2012)) {
$setArray[2] = 500;
}
So that only sections of the string which have 2012 in them are updated.
Any pointers would be greatly appreciated.
Cheers
Rich