Reputation: 67
I'm storing an array of comma separated values in my database in a column called line_services
. The data in the column looks like 1,1,1,1,0,0,0
and I have a prepared statement where I bind the results of this column to the variable $line_services
. In this prepared statement I have the following code after my fetch.
foreach(explode(',', $line_services) as $lineservices) {
if ($lineservices == '1') {
strtolower(str_replace('','_',$service_name.'_total')) = ((($service_tax / 100) * $service_cost) + 80.00) * $line_artwork_hours; //1 hour
}
if ($lineservices == '2') {
strtolower(str_replace('','_',$service_name.'_total')) = ((($service_tax / 100) * $material_cost) + $material_cost) * $line_product_sqft; //2 sq ft
}
if ($lineservices == '3') {
strtolower(str_replace('','_',$service_name.'_total')) = (($service_tax / 100) * ($line_L + $line_W)) + ($line_L + $line_W); //3 linear
}
if ($lineservices == '4') {
strtolower(str_replace('','_',$service_name.'_total')) = (($service_tax / 100) * (($line_L + $line_W) * 2) * .75) + (($line_L + $line_W) * 2) * .75; //4 linear
}
}
I'm getting the following error:
Can't use function return value in write context
When I do a var_dump
on $line_services
it is coming up NULL
even though there is data in the column. The line_services column in the database is a varchar if that makes any difference.
Upvotes: 0
Views: 43
Reputation: 78994
I assume you are trying for a variable variables? Rarely if ever a good idea, but you can use the curly syntax:
${strtolower(str_replace('','_',$service_name.'_total'))} = 'whatever';
Consider using an array instead:
$total[$service_name] = 'whatever';
Upvotes: 1
Reputation: 191
For starters, you are overwriting your variable in you foreach.
foreach(explode(',', $line_services) as $lineservices)
Switch this to:
foreach(explode(',', $line_services) as $lineservice)
Second of all, what are you expecting to happen here?
strtolower(str_replace('','_',$service_name.'_total')) = ((($service_tax / 100) * $service_cost) + 80.00) * $line_artwork_hours;
You are trying to assign a value to the strtolower function?
Upvotes: 0
Reputation: 31
You are using an assignment to strtolower, and you can't do this. Check your code:
strtolower(str_replace(...)) = ...;
That doesn't make any sense. What are you trying to do? You are not assigning the result of (($service_tax / 100) * ($line_L + $line_W)) + ($line_L + $line_W)
(for example) to any variable.
Upvotes: 2