hakeryk2 Posted April 14, 2017 Posted April 14, 2017 (edited) Hello dev's I have probably easy question for advanced prestashop and php developers. I will show an example what I want to achieve in simpler way. Let's start with just example. Currently when I want to retrieve ie all employees ID I will use: $employees_id = Db::getInstance()->executeS(' SELECT id_employee FROM '._DB_PREFIX_.'employee '); but the output that I will receive with ddd($order_employees_id) is Array ( [0] => Array ( [id_employee] => 1 ) [1] => Array ( [id_employee] => 2 ) [2] => Array ( [id_employee] => 3 ) [3] => Array ( [id_employee] => 4 ) [4] => Array ( [id_employee] => 5 ) [5] => Array ( [id_employee] => 7 ) ) and I have to use $ids = array(); foreach ($employees_id as $key => $value) { $ids[] .= $employees_id[$key]['id_employee'] ; } to receive array type that I want which is Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 7 ) Maybe there is other way to acomplish that without using foreach every time? It is just much easier to operate sometimes. Any help will be very appreciated:) Edited April 14, 2017 by hakeryk2 (see edit history) Share this post Link to post Share on other sites More sharing options...
ventura Posted April 14, 2017 Posted April 14, 2017 Better try it with the function Employee::getEmployees(true); /** true by active employees status */ Share this post Link to post Share on other sites More sharing options...
hakeryk2 Posted April 14, 2017 Posted April 14, 2017 Well, that was just an example I was taking about retrieving info into simple array and employees were just an example but thanks for the function anyway. Share this post Link to post Share on other sites More sharing options...
ventura Posted April 14, 2017 Posted April 14, 2017 Sure. but in anycase it is always better get a default function for this kind of methods. In your query method you can use $onlyIds = array_column($employees_id, 'id_employee'); 2 Share this post Link to post Share on other sites More sharing options...
hakeryk2 Posted April 14, 2017 Posted April 14, 2017 Thank You! I didn't know that this functions exists Share this post Link to post Share on other sites More sharing options...
Ali Samie Posted January 25, 2022 Posted January 25, 2022 On 4/14/2017 at 1:45 PM, ventura said: Sure. but in anycase it is always better get a default function for this kind of methods. In your query method you can use $onlyIds = array_column($employees_id, 'id_employee'); Thanks a lot. Its just what i needed Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now