barryccampbell
Technical User
I have variables pulled from mysql, ex $cs & $counter. $cs has contains 3 numbers, ex 100,200,300 and $counter has 2 names, ex john,bob. In actuality, there are a total of 7 variables with between 2 and 3 data terms inside each variable. I'm trying to explode each variable in the array, attach a letter to each exploded variable (A,B,C) that corresponds with each data point within the variable, and use the specific variable ($csA) in future calculations and display in a form. So far, this is my code:
In the first array, $combine_array, the first variable is what I want to manipulate (add a letter A or B or C), the second variable contains the data.
The last 2 lines of code are my problem. The commented section
is what I want to do, but is obviously not right. The last line gives me exactly what I want in display terms, but does not set $csA=100, the first of the 3 numbers (100,200,300). Obviously, I'm not a professional and there is probably a better way, but this is where my thought process has led me. Any help would be appreciated.
I have this done in long form: pull the data from mysql, set each field equal to a variable, explode each individual variable, set each individual variable ($csA, $csB, $csC) to the corresponding exploded value, then move on to $dsd_purch and do it all over again. I'm trying to condense the code and learn something new. Thanks.
Code:
$combine_array=array(
array('$cs',"$cs"),
array('$dsd_purch',"$dsd_purch"),
array('$wh_purch',"$wh_purch"),
array('$dsd_cred',"$dsd_cred"),
array('$sales',"$sales"),
array('$counter',"$counter"),
array('$inv_time',"$inv_time")
);
$letter_array=array("A","B","C");
for($ix=0;$ix<count($combine_array);$ix++){
if($combine_array[$ix][1]!=NULL){
$combine_array[$ix][1]=explode(",",$combine_array[$ix][1]);
for($ix_l=0;$ix_l<count($combine_array[$ix][1]);$ix_l++){
//$combine_array[$ix][0]."".$letter_array[$ix_l]=$combine_array[$ix][1][$ix_l];
echo $combine_array[$ix][0]."".$letter_array[$ix_l]." ".$combine_array[$ix][1][$ix_l]."<br>";
}
}
}
In the first array, $combine_array, the first variable is what I want to manipulate (add a letter A or B or C), the second variable contains the data.
The last 2 lines of code are my problem. The commented section
Code:
//$combine_array[$ix][0]."".$letter_array[$ix_l]=$combine_array[$ix][1][$ix_l];
I have this done in long form: pull the data from mysql, set each field equal to a variable, explode each individual variable, set each individual variable ($csA, $csB, $csC) to the corresponding exploded value, then move on to $dsd_purch and do it all over again. I'm trying to condense the code and learn something new. Thanks.