-1

Hi I have small problem with changing colour of font from array, printing things works fine.

<?php print $Pobierz_wsyzstkie [1]; ?>
<?php echo $Pobierz_wsyzstkie [3]; ?>

This works fine, write what they should. But if i try to colour the array output with code like this:

   <?php echo "<span style='color:blue;'>$Pobierz_wsyzstkie 
   [3]</span>"; ?>

I get coloured text but is not text from array, this shows "Array [3]".

Johannes
  • 64,305
  • 18
  • 73
  • 130
Krystian
  • 3
  • 1

2 Answers2

0

Write it like this (note the quotes and dots to separate and connect PHP and HTML string output):

<?php echo "<span style='color:blue;'>".$Pobierz_wsyzstkie[3]."</span>"; ?>
Johannes
  • 64,305
  • 18
  • 73
  • 130
0

You have a space between your variable and your square brackets. This is the direct cause of the issue. Also, correctly concatenate your variables within your string.

Here;

<?php 
   echo "<span style='color:blue;'>".$Pobierz_wsyzstkie[3]."</span>";
?>

Best Practises :

  • The PHP open and close tags should be on their own lines.
  • Array references (keys) should not have a space between them and their array variable name ($Pobierz_wsyzstkie[3] not "$Pobierz_wsyzstkie [3]")
  • Learn about the correct PHP String Concatenation.
  • PHP variables ($Pobierz_wsyzstkie) should start with a lower case letter.
  • CSS styles should not be inline but instead should be in their own CSS file.
Martin
  • 22,212
  • 11
  • 70
  • 132