Add constant to each key of an array

Asked

Viewed 26 times

1

How to include a constant in a given array key. Example:

Unchanged array:

   array (size=3)
  0 => 
    array (size=3)
      'id' => string '1' (length=1)
      'image' => string '1.jpg' (length=5)
      'carro' => string 'bmw' (length=12)
  1 => 
    array (size=3)
      'id' => string '2' (length=1)
      'image' => string '2.jpg' (length=5)
      'carro' => string 'mercedes' (length=17)
  2 => 
    array (size=3)
      'id' => string '3' (length=1)
      'image' => string '3.jpg' (length=5)
      'carro' => string 'bentley' (length=9)

Array with change:

array (size=3)
  0 => 
    array (size=3)
      'id' => string '1' (length=1)
      'image' => string 'http://exemplo.com/1.jpg' (length=5)
      'carro' => string 'bmw' (length=12)
  1 => 
    array (size=3)
      'id' => string '2' (length=1)
      'image' => string 'http://exemplo.com/2.jpg' (length=5)
      'carro' => string 'mercedes' (length=17)
  2 => 
    array (size=3)
      'id' => string '3' (length=1)
      'image' => string 'http://exemplo.com/3.jpg' (length=5)
      'carro' => string 'bentley' (length=9)
  • What is the constant and in which key?

  • What you want is to build the url of the image prefixed http://www.exemplo.com/ in every field image ?

  • At what point does this constant go into action? or does it have to scan this array and assign? your question is incomplete could explain these points.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.