tags:

views:

23

answers:

1

$result = $mysql->callSP('STOREDPE1',$in); $arr_tmp=array(); foreach ($result['record'] as $rows) { echo "one value"; if(!empty($rows)){ echo "Two Value"; $arr_tmp[$rows['field1']] = $rows['field2']; } }

return $arr_tmp;        

when i say var_dump($result)it has two values in array .But when i Execute "arr_tmp"it is returned with one value

out put of var_dump($result)

["param"]=> array(4) { ["whcode"]=> string(5) "001" ["mode"]=> string(1) "A" ["stock_type"]=> string(4) "AAA" ["process_name"]=> string(7) "AAAA" } ["record"]=> array(2) { [0]=> array(3) { ["Field1"]=> string(5) "value1" ["Field2"]=> string(1) "CCC" ["Field3"]=> string(4) "BCC" } [1]=> [0]=> array(3) { ["Field1"]=> string(5) "value1" ["Field2"]=> string(1) "CCC" ["Field3"]=> string(4) "BCC" } } }

output of var_dump (arr_tmp)

[1]=> [0]=> array(3) { ["Field1"]=> string(5) "value1" ["Field2"]=> string(1) "CCC" ["Field3"]=> string(4) "BCC" }

Both the array values seems  to be same 

I have the values overwriting in the array

+2  A: 

Very hard to understand and read with the bad formatting, please take care to post it with proper formatting.

I think the answer is this:

$result = $mysql->callSP('STOREDPE1',$in); 
$arr_tmp=array();
foreach ($result['record'] as $rows) { 
    echo "one value"; 
    if(!empty($rows)){ 
        echo "Two Value"; 
        $arr_tmp[][$rows['field1']] = $rows['field2']; 
    } 
}

var_dump($arr_tmp);

That should store both sets of data, you just needed to make it a multi-dimensional array. That is, if that is your question and I did not mis-read it through that garbled text above.

Update

This option is not recommended better to learn how to use arrays, simply posted for an example of usage:

$result = $mysql->callSP('STOREDPE1',$in); 
$arr_tmp=array();
$i=0;
foreach ($result['record'] as $rows) { 
    echo "one value"; 
    if(!empty($rows)){ 
        echo "Two Value"; 
        $arr_tmp[][$rows['field1'] . "_$i"] = $rows['field2']; 
    }
    $i++; 
}

var_dump($arr_tmp);
Brad F Jacobs
Thanks It helped me a lot thanks a lot.
Someone
@Premiso :I dont want to have double dimensional array .It is very tough to assign values and need to change a lot of thing can we use the same above code and assign the same values without double dimensional
Someone
The only way would be to make the field names unique, which they currently are not. You can append a 1 to the field names (example given) but it is much better to learn how to work with arrays.
Brad F Jacobs