I read this questions
How do I insert a variable into a PHP array?
But I think it is no more valid in php 7.
Fatal error: Constant expression contains invalid operations in D:\Business_Work\Apache24\htdocs\garbagevalue\books_solution\models.php on line 82
I'm creating an array using which I will generate HTML forms.
In the SELECT
input of the form, I have to give options
dynamically fetched from some table. But the problem is I can't put anything dynamic on the array.
getIds
method returns the array of options
for select
field.
class Chapters extends Models{
protected $tableName = APP.'_chapters';
protected $formDef = [
['Chapter Number', 'text', ['required']],
['Chapter Name', 'text', ['required']],
['Keywords', 'text', ['required']],
['Description', 'text', ['required']],
['Select Book', 'select', ((new Chapters())->getIds((new Books())->$tableName))]
];
}
}
Argument of the method getIds()
is a string and it returns an array (I've tested that function). This function is the member of the Base class Models
.
public function getIds($table, $field=NULL, $value=NULL){
require BASE_PATH.'/ap-admin/connection.php';
if($field == NULL){
$sql = "SELECT id FROM ".$table;
}
else{
$sql = "SELECT id FROM ".$table." WHERE ".$field." = ".$value;
}
$result = $con->query($sql);
return $result->fetch_row();
}
So How I can put a variable or dynamic data in a php array in php7 ?