dsij89625 2013-06-30 04:57
浏览 48
已采纳

如何在php中删除数组到字符串转换错误

i am working on php i have dynamic array i need to get the array result store in some variable i encounter the error :array to string conversion coding

   <?php
require_once('ag.php');
class H
 {
    var $Voltage;
    var $Number;
    var $Duration;
function H($Voltage=0,$Number=0,$Duration=0)
     {
        $this->Voltage = $Voltage;
        $this->Number = $Number;
        $this->Duration = $Duration;
    }}
//This will be the crossover function. Is just the average of all properties.
function avg($a,$b) {
return round(($a*2+$b*2)/2);
}
//This will be the mutation function. Just increments the property.
function inc($x)
 {
    return $x+1*2;
}
//This will be the fitness function. Is just the sum of all properties.

function debug($x) 
{
    echo "<pre style='border: 1px solid black'>";
    print_r($x);
    echo '</pre>';
    }
//This will be the fitness function. Is just the sum of all properties.
function total($obj) 
{
return $obj->Voltage*(-2) + $obj->Number*2 + $obj->Duration*1;
}
$asma=array();
for($i=0;$i<$row_count;$i++) 
{
$adam = new H($fa1[$i],$fb1[$i],$fcc1[$i]);
$eve = new H($fe1[$i],$ff1[$i],$fg1[$i]);
$eve1 = new H($fi1[$i],$fj1[$i],$fk1[$i]);
$ga = new GA();
echo "Input"; 
$ga->population = array($adam,$eve,$eve1);
debug($ga->population);
$ga->fitness_function = 'total';    //Uses the 'total' function as fitness function
$ga->num_couples = 5;               //4 couples per generation (when possible)
$ga->death_rate = 0;                //No kills per generation
$ga->generations = 10;              //Executes 100 generations
$ga->crossover_functions = 'avg';   //Uses the 'avg' function as crossover function
$ga->mutation_function = 'inc';     //Uses the 'inc' function as mutation function
$ga->mutation_rate = 20;            //10% mutation rate
$ga->evolve();                      //Run
echo "BEST SELECTED POPULATION";
debug(GA::select($ga->population,'total',3)); //The best
 $array=array((GA::select($ga->population,'total',3))); //The best }

?>
  <?php

$comma_separated = implode(",", $array); 
echo $comma_separated; // lastname,email,phone
?

> i apply implode function but its not working it display the error of : Array to string conversion in C:\wamp\www\EMS3\ge.php on line 146 at line $r=implode($rt,",");

  • 写回答

1条回答 默认 最新

  • dqp21271 2013-06-30 06:22
    关注
    <script>
    if (   ($textboxB.val)==31.41)
    {
    </script>
    
    <?php echo "as,dll;g;h;'islamabad"; ?>
    
    <script>} </script>
    

    You are running your java script code in PHP, I havent implemented your code just checked and found this bug.You can get the value by submitting the form also

    ---------------------------- Answer For your Second updated question------------------------

    <?php
    $array = array(
          "name" => "John",
          "surname" => "Doe",
          "email" => "j.doe@intelligence.gov"
       );
    $comma_separated = implode(",", $array); // You can implode them with any character like i did with ,
    
    echo $comma_separated; // lastname,email,phone
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退