开发者

php breaking it down

开发者 https://www.devze.com 2022-12-13 04:49 出处:网络
I was looking at some codeandI came across this line: Machine drink[] = {{\"Coke\", .75,7}开发者_如何学运维, {\"Sprite\", .55, 2}, { \"Pepsi\", 1.00, 5}}

I was looking at some code and I came across this line:

 Machine drink[] = {{"Coke", .75,7}开发者_如何学运维, {"Sprite", .55, 2}, { "Pepsi", 1.00, 5}}

At first I thought it was an array, but in php we don't create arrays like this, unless if this is some advanced technique for creating an array that I am not aware of.

And why is it constructed like this?

Coke is a soda.

.75 is the price

And 7 is quantity.


Somewhat broken code, but let's pseudo the intentions:

This is an array called drink of object Machine that is being assigned a new element consisting of an array of arrays, where each element contains drink name and then a float (price) and an integer (quantity).


php > Machine drink[] = {{"DrSalty", .75,7}, {"LemonDew", .55, 2}, { "ChocuRu", 1.00, 5}}

Parse error: syntax error, unexpected T_STRING in php shell code on line 1

This isn't php.


At first I thought it was javascript object notation (json), but I don't think it's quite right for that either.

(see the json_encode() and json_decode() functions in the php docs)

0

精彩评论

暂无评论...
验证码 换一张
取 消