I am new to PHP, And am creating a data string, which i have written like this.
$data = $product['id']. "/" . $product['name'] . "/" .$product['price'];
I don't know if there is another better way to create this String.
I am new to PHP, And am creating a data string, which i have written like this.
$data = $product['id']. "/" . $product['name'] . "/" .$product['price'];
I don't know if there is another better way to create this String.
PHP can interpolate array values inside double quotes if they are surrounded with {}:
$data = "{$product['id']}/{$product['name']}/{$product['price']}";
If you remove the quotes around the keys you don't need the curly braces and it will become even simpler:
$data = "$product[id]/$product[name]/$product[price]";
You could use sprintf for it, which has the advantage of giving a better overview:
sprintf('%d/%s/%f', $product['id'], $product['name'], $product['price']);
Other way:
$data = "Name";
$date .= $product['id'];
$date .= "AND etc..";