Ahmed Ahmed - 1 month ago 7
PHP Question

string to array as variable

I have profile id stored in my sql database
this is my php code

public function get_profile_id()
{
$this->dao->select('profile_id');
$this->dao->from($this->getTable());
$result = $this->dao->get();
if( !$result ) {
return array() ;
}
return $result->result();
}

$details = Modelbuttons::newInstance()->get_profile_id();
var_dump ($details) ; ?>


I get this response

array (size=2)
0 =>
array (size=2)
'id' => string '1' (length=1)
'profile_id' => string '57f03c4d66f4a4f6111111111' (length=24)
1 =>
array (size=2)
'id' => string '2' (length=1)
'profile_id' => string '55534512113e8042222222222' (length=24)


i want send this profile id to an APi with this call

$newArr = Modesend::newInstance()->getprofile();
foreach($newArr as $a) {
$values[] = explode(' ', $a['profile_id'])[0];
$profile = "" . implode("','", $values). "";
$data = array('profile_ids' => array($profile));


this call not work for me can you help me !

this is the success API call

$data = array('profile_ids' => array('57f03c4d66f4a4f6111111111','55534512113e8042222222222')));

Answer

If you want to store all values in array you can simply define an array before foreach loop

$data = [];
$newArr = Modesend::newInstance()->getprofile();
foreach($newArr as $a) {
 $data[] = $a['profile_id'];
}
var_dump($data);