Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to implode and foreach get

I try to take each "name" and send it to my database for verification
the problem is that I can’t take each one and go through the foreach

$name = $this->UserSkills->where('id', session()->get('id'))->first();
print_r($name) // return Array ( 
                          [id] => 5 
                          [user] => 15 
                          [name] => name,name1,name2,name3,name4
                         )

$name = implode(",", $name['name']);

foreach($name as $row) {
    $setname[] = $this->checkName->getIDbyName($row['name']);
}

$setname = implode(",", $setname);

$data['id_name'] = $setname;

finally I want him back

echo $data['id_name'] // return: 1,4,8,367, etc...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your first usage of implode is incorrect, you need explode to take a string and make it into an array.

<?php

$name = $this->UserSkills->where('id', session()->get('id'))->first();

$name = explode(",", $name['name']);

foreach($name as $row) {
    $setname[] = $this->checkName->getIDbyName($row);
}

$setname = implode(",", $setname);

$data['id_name'] = $setname;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading