increment object name with numbers in a loop [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am having trouble to increment the name of an object within a loop but the following doesn't not seem to work
I need to increment $serie1->addPoint to $serie2->addPoint, $serie3->addPoint etc..
$i = 1;
foreach ($users as $agent) {
$serie{$i}->addPoint...
$i +=1;
}
I get an error Notice: Undefined variable: serie in
I also tried $serie.$i->addPoint... but that produced an error as well Fatal error: Call to a member function addPoint().
However, it does work if I manually assign the increments like so $serie1->addPoint etc..

It cannot be : $serie{$i}
It should be: ${'serie'.$i}
A short Demo

Related

Undefined Index with existing variables [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I know that with this error the variable doesn't exist in the array. Weirdly when I check the array, it does exists...... Am I blind? Am I missing something?
Undefined index: uuid on line 141
foreach($orderDetails->line_items as $orderLineItem) {
foreach($returnLineItems as $itemKey => $value){
if($orderLineItem->uuid == $returnLineItems[$itemKey]['uuid']) { //Line 141
}
}
}
Although this is an object:
dd($orderLineItem->uuid) => 236cb65b-a602-4422-a11a-803bd7dbf05d
The array:
dd($returnLineItems[$itemKey]['uuid'] => 236cb65b-a602-4422-a11a-803bd7dbf05d
Upon Comment request the DD of the entire
Ok after two hours I found it...
I was regenerating $returnLineItems in the foreach loop, causing the array to miss UUID.
Thanks for helping all!

Why this collection is returning this error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
can someone please show where is the error ?
$material = DB::table('material_user')->where('material_user.id', $id)
->leftjoin('users', 'users.id','=','material_user.user_id')
->leftjoin('materials', 'materials.id','=','material_user.material_id')
->select('users.first_name','users.last_name','users.sexe','materials.serial','materials.name','material_user.created_at')
->get();
dd($material->first_name);
Exception
Property [first_name] does not exist on this collection instance.
get() returns a collection. So you have to iterate over the collection to get the first_name for e.g
foreach ($material as $object)
echo $object->first_name;
endforeach
Or you can get the single record using below & can access first_name directly
$object = $material->first();
echo $object->first_name

Receiving Fatal error: Call to a member function title() on array [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm learning PHP POO and I'm having trouble using the variables to the META TITLE and DESCRIPTION. I've checked all the topics related but couldn't find an example close to my problem.
Here's the part of the code concerned :
$model_Article = new Model_Article($db);
$contenuArticle = $model_Article->StockageDonneesById($id);
// die(var_dump($contenuArticle));
$affichage = new View_Article($contenuArticle->title(),$contenuArticle->description());
$affichage->setContenuArticle($contenuArticle);
$affichage->head();
$affichage->nav();
$affichage->genererArticle();
$affichage->foot();
The variables $contenuArticle->title()and $contenuArticle->description() are supposed to generate TITLE and DESCRIPTION metas, but they send back the error Fatal error: Call to a member function title() on array
Var_dump show that the Array isn't empty and return the right content.
I'm pretty sure it's a common error but I'm lacking experience to point it. Let me know if I can provide more specific intels on my files.
Using var_dump($contenuArticle) shows the return of $model_Article->StockageDonneesById($id) is an array, with 1 element.
changing line 6 to:
$affichage = new View_Article($contenuArticle[0]->title(),$contenuArticle[0]->description());
Solved the issue

How to deal with "Undefined index: " [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
if(!isset($aProdcut[$eachYear][$store][$base])){
$aProdcut[$eachYear][$store][$base] = 0;
}
$aProduct[$eachYear][$store][$base] += $row['total_price'];
Undefined index: MARC. MARC is from $base.
Who can give me some hints?
You have a typo there $aProdcut vs $aProduct
The code should not result in undefined index if you have an $aProduct variable, which is an array and has an index value of $eachYear, which is, in turn another array, which has an index value of $store, since, in that case
isset($aProdcut[$eachYear][$store])
is true. If that is true and it does not have a $base index value, then it is created and initialized with 0. Later, when you use it, it will surely exist. So, the issue is probably that $aProduct[$eachYear] does not exist or $aProduct[$eachYear][$store] is not set. Make sure that everything exists, not just the innermost index and then the problem will be probably fixed. If the problem still persists, then you should check whether some other things are causing it, like multi-threading.

PHP: Parse Error After Assigning Variable? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
How come this php script is returning a parse error?
When I remove the line that assigns argv to a variable, PHP won't return a parse error. Furthermore, it says the parse error is on the print line.
<?php
$points = $argv[1]
print($argv[1])
?>
PHP statements should end with ;
$points = $argv[1];
^
print($argv[1]);
^

Categories