これはおそらく私がこれまでに尋ねた中で最もばかげた質問であることはわかっています...しかし、私は基準点を探し続けており、非常に多くのランダムな質問があり、見つけるのが最も困難です. 正しい構文の問題である可能性が最も高いことはわかっていますが、私の人生では、多くの試行錯誤の末、おそらく質問する方が簡単だとわかっています....(また、 lastInsertId() は可能な解決策にはなりません他の省略されたコードがあるため)...正しく返すにはグローバル変数である必要があります...私の理解する限り....明示的ではありません
質問: この変数を正しくエコーするにはどうすればよいですか:
エコーコード
$customer = new SoClassy();
$var1 = "test 1";
$var2= "test 2";
$var3= "test 3";
try {
$customer->add_function($var1,$var2,$var3);
$last_insert_id= $customer->$return_this_variable;
echo "HERE: ";
echo $last_insert_id;
}
catch (Exception $e) {
print "Error: " . $e->getMessage();
}
クラスコード (異なる *.php)
function add_function($var1,$var2,$var3)
{
$data = array(
'position_one' => $var1,
'position_two' => $var2,
'position_three' => $var3
);
try {
$this->db->insert($this->config->database->tables->table_name, $data);
$return_this_variable = $this->db->lastInsertId();
return $return_this_variable;
}
catch ...{}
catch ...{}
}