2013-06-30 71 views
0

我對PHP的工作,我有動態數組,我需要得到一些變量數組結果店裏我遇到的錯誤:array to string conversion 編碼如何刪除陣列字符串轉換錯誤在PHP

<?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 
? 

> 我申請破滅的功能,但它不工作 它在行顯示的: Array to string conversion in C:\wamp\www\EMS3\ge.php on line 146錯誤$r=implode($rt,",");

+0

你又來了嗎?同樣的問題? – DevZer0

+0

becoz我沒有得到解決方案 – aniya

+0

你想在你的php代碼中使用textboxB的值(if else條件)嗎? –

回答

1
<script> 
if ( ($textboxB.val)==31.41) 
{ 
</script> 

<?php echo "as,dll;g;h;'islamabad"; ?> 

<script>} </script> 

您正在運行Java腳本代碼的PHP ,我沒有執行你的代碼,只是檢查並發現了這個bug。你可以通過提交表單來獲取值

----------------------- -----回答你的第二個更新問題------------------------

<?php 
$array = array(
     "name" => "John", 
     "surname" => "Doe", 
     "email" => "[email protected]" 
    ); 
$comma_separated = implode(",", $array); // You can implode them with any character like i did with , 

echo $comma_separated; // lastname,email,phone 
?> 
+0

謝謝先生的工作 – aniya

+0

不客氣:) –

+0

先生我有另一個issuse,如果你可以解決它我將感謝你與它相關的數組到字符串轉換錯誤 – aniya