skip to Main Content

PHP cant add new object keys in foreach loop

I want to create new object keys in foreach loop so I write: $all_variants = $p->variants; foreach ($all_variants as $a) { $a->discount_price = $a->price; $a->original_price = $a->price; $a->button_text = 'BUY'; } but this code wont create new keys (discount_price, original_price,…

VIEW QUESTION

How to iterate an array to count elements PHP?

I wanna know how to iterate an array to count elements in PHP, I've trying next, foreach ($items as $item) { $tm[$item->provider->name] = []; foreach ($items as $item) { $tm[$item->provider->name][$item->product->brand->name] = isset($tm[$item->provider->name][$item->product->brand->name]) ? $tm[$item->provider->name][$item->product->brand->name] + 1 : $tm[$item->provider->name][$item->product->brand->name] = 1;…

VIEW QUESTION

Laravel foreach loop database

I'm kinda new to programming in general. I'm trying to loop through a table. There is a connection to the DB already. It's giving me - "Object of class IlluminateDatabaseMySqlConnection could not be converted to string" class ProductController extends Controller…

VIEW QUESTION
Back To Top
Search