PHP数组。 将表中的每一行数据更改为字符串,然后传递给数组

I am trying to use to a loop to pull all rows from a table, and change every row to a string then pass to an array. Here is the script I am currently working on.

PHP:

function toggleLayers(){
    $toggleArray = array($toggle);
    for($i=0;$i<$group_layer_row;$i++){
        $toggle=mb_convert_encoding(mssql_result ($rs_group_layer, $i, 0),"UTF-8","SJIS")."_".mb_convert_encoding(mssql_result ($rs_group_layer, $i, 1),"UTF-8","SJIS");
        return $toggleArray($toggle);
    }
}    

Right now it only returns a string without passing to the array. Been looking and can't seem to find anywhere or anyone that can explain this to me in plain english.

Hope you can help. Thanks

I think you will gonna change your code to something like this:

$toggleArray = array();
for ($i = 0; $i < $group_layer_row; $i++) {
   // push your string onto the array
   $toggleArray[] = mb_convert_encoding(mssql_result($rs_group_layer, $i, 0), "UTF-8", "SJIS") . "_" . mb_convert_encoding(mssql_result ($rs_group_layer, $i, 1), "UTF-8", "SJIS");
}
return $toggleArray;

I have no idea what vars are what in your example, but if you wanted to loop through an array and change its contents, here's how i'd do it:

$myArray = array( 'thing', 'thing2' );
// the ampersand will pass by reference, i.e.
// the _Actual_ element in the array
foreach( $myArray as &$thing ){
  $thing .= " - wat?!";
}

print_r( $myArray );

will give you

[0] =>
  'thing - wat?!'
[1] =>
  'thing2 - wat?!'