-1

I have 12 records in my array but I only want to print out one specific value, I have tried the following:

<p><?php echo $percentSKU['PercentageSales'][0]; ?></p>

But this is printing out the first character not the first complete value.

For example. If my records were: Monday, Tuesday, Wednesday etc. I want to just get Monday but its just giving me 'M'.

Can someone point me in the right direction?

PHPNewbie
  • 247
  • 4
  • 19
  • 3
    What is the output of `print_r($percentSKU);`? – Rizier123 Nov 21 '16 at 14:17
  • Array ( [BaseCard] => CW000718-W [SalesGroup] => Draught Lager [PercentageSales] => 26.22 ) is the output – PHPNewbie Nov 21 '16 at 14:19
  • Your array doesn't seem to contain what you think it does. You should add the code you are using to build it and the structure you are more or less aiming for. – jeroen Nov 21 '16 at 14:19
  • 1
    Your array just has 3 elements not 12. Also it is a simple one dimensional array, means you don't have a second dimension. Just use `$percentSKU['PercentageSales']` to access the element. – Rizier123 Nov 21 '16 at 14:21
  • Okay, so I am getting 12 results, is there anyway I can just print out the final 26.22 of result 6 for example? – PHPNewbie Nov 21 '16 at 14:24

1 Answers1

3

Sounds like $percentSKU['PercentageSales'] is already a string by itself. Using [0] on a string gets you the first character, which is exactly what happens. Just don't specify anything to get the whole string:

echo $percentSKU['PercentageSales'];
Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122