Jump to content

Recommended Posts

<?php
    	foreach($customers AS $key => $value) {
    		$fpdf->Cell(30, 10, $key, 1, 0, 'C');
    		$fpdf->Cell(30, 10, $value['forecast'], 1, 0, 'C');
    		$fpdf->Cell(30, 10, $value['actual'], 1, 0, 'C');
    		$fpdf->Cell(30, 10, $value['gam'], 1, 0, 'C');
    		$fpdf->Cell(30, 10, $value['actual'] + $value['gam'] - $value['forecast'], 1, 1, 'C');
    		foreach($value['products'] AS $key2 => $value2) {
    			$fpdf->Cell(30, 10, '', 1, 0, 'C');
    			$fpdf->Cell(30, 10, $key2, 1, 0, 'C');
    			$fpdf->Cell(30, 10, $value2['forecast'], 1, 0, 'C');
    			$fpdf->Cell(30, 10, $value2['actual'], 1, 0, 'C');
    			$fpdf->Cell(30, 10, $value2['gam'], 1, 0, 'C');
    			$fpdf->Cell(30, 10, $value2['actual'] + $value2['gam'] - $value2['forecast'], 1, 1, 'C');
    		}
    		
    	}
?>

Why no matter how I do this I always get, a

Warning: Cannot use a scalar value as an array in D:\xampp\htdocs\rolfdev\app\views\reconcile\area_customer_pdf.thtml on line 30

 

Warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\rolfdev\app\views\reconcile\area_customer_pdf.thtml on line 30

[/quote

error.

There is an array inside $value['products'] but it returns that for some reason.

Any advice?

Link to comment
https://forums.phpfreaks.com/topic/71861-solved-scalar-error/
Share on other sites

@ MmmVomit

I can't show customer's "data" because it's a private project.

The original array is called products.  I have split it into 2 arrays

products['customers'] is going into customers and the other part somewhere else.

I am focusing on customers.

Which is now the $customers array.

Inside it are some values, and one array.  Which is products.

customers[value]

customers[value2]

customers[value3]

customers[products] -> array

inside that array are

product id -> values.

For each one.

 

Note:

@mgallforever

I tried that, as well as unsetting each one at the end both.  No luck.

Link to comment
https://forums.phpfreaks.com/topic/71861-solved-scalar-error/#findComment-361976
Share on other sites

Yes, customers is the array customers.

It works fine,without the second foreach.

$customers['products'] howeverwhich I am trying to access in the second

foreach is, but funny.

It's

$customers['customerid']['products'] is an array of product id's

Like

$customers['customerid']['products -> array (

$prod_id = array (

 

value = whatever

value2 = whatever again

value3 = something else

)

 

)

That's basically it.

Link to comment
https://forums.phpfreaks.com/topic/71861-solved-scalar-error/#findComment-361982
Share on other sites

It's saying you can't do this ie use a var as a scalar value then try to use it as an array

 

<?php
$customers = 0;

$customers[0] = 'fred';
?>

[pre]

--> Warning: Cannot use a scalar value as an array in test.php on line 4

[/pre]

 

Link to comment
https://forums.phpfreaks.com/topic/71861-solved-scalar-error/#findComment-361987
Share on other sites

Ok, I tried that just now.

I don't understand exactly what this error is.

I know, btu I don't know how to fix it.

 

the answer is don't use a scalar as an array.

 

<?php
$customers = 0; // Here $customers is a scalar variable with value 0.
// DO NOT TRY TO ASSIGN VALUES TO IT LIKE AN ARRAY

$customers[0] = 'fred'; // Here we're trying to assign a value to $customer as if it's an array, but it's a scalar.
// DON'T DO THAT!
?>

Link to comment
https://forums.phpfreaks.com/topic/71861-solved-scalar-error/#findComment-362015
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.