0

I'm trying to edit Open Cart stock levels and I am just a beginner in php.

I am currently displaying the quantity of stock left (numeric only), which is stored within $product_info['quantity'].

$data['stock'] =  ($product_info['quantity']);  

This works fine.

I am trying to add text to the end of the quantity so it would say for example 3 remaining in stock:

$data['stock'] =  ($product_info['quantity']) + "remaining in stock"; //(doesn't work)

I don't know the mark up to add text, I've tried a few things and no luck I can only get the number value to show.

2
  • 3
    In PHP, + is addition; . is concatenation Commented Jan 7, 2018 at 19:22
  • 1
    And you don't need any parenthesis like "(" or ")". Commented Jan 7, 2018 at 19:27

1 Answer 1

1

You should use . instead of +:

$data['stock'] =  ($product_info['quantity']) . "remaining in stock";

It is explained in the String Operators entry of the PHP Manual:

There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments.

Sign up to request clarification or add additional context in comments.

Comments