You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+212Lines changed: 212 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,6 +136,218 @@ Access granted!
136
136
App Version: 1.2.3
137
137
```
138
138
139
+
## PHP Script Language Reference
140
+
141
+
This section provides a comprehensive overview of the PHP Script language syntax, including all supported statements, expressions, and their variations.
142
+
143
+
### 1. Basic Statements and Expressions
144
+
145
+
#### Echo Statement
146
+
147
+
The `echo` statement is used to output values.
148
+
149
+
```javascript
150
+
echo 'Hello World!';
151
+
echo 123;
152
+
echo true;
153
+
echo LINEBREAK; // Outputs a new line
154
+
```
155
+
156
+
#### Variable Assignment
157
+
158
+
Variables can be assigned values using the `=` operator. Variables are dynamically typed.
159
+
160
+
```javascript
161
+
myVariable =10;
162
+
anotherVariable ='some text';
163
+
booleanVariable =true;
164
+
```
165
+
166
+
#### Literals
167
+
168
+
PHP Script supports the following literal types:
169
+
170
+
-**Numbers:** Integers and floating-point numbers.
171
+
```javascript
172
+
number =123;
173
+
floatNumber =3.14;
174
+
```
175
+
-**Strings:** Enclosed in single or double quotes.
176
+
```javascript
177
+
singleQuoteString = 'Hello';
178
+
doubleQuoteString = "World";
179
+
```
180
+
-**Booleans:**`true` and `false`.
181
+
```javascript
182
+
isTrue = true;
183
+
isFalse = false;
184
+
```
185
+
-**Null:**`null`.
186
+
```javascript
187
+
emptyValue = null;
188
+
```
189
+
-**LINEBREAK:**A special keyword representing a newline character.
190
+
```javascript
191
+
echo 'Line 1' ~ LINEBREAK ~ 'Line 2';
192
+
```
193
+
194
+
### 2. Operators
195
+
196
+
#### Arithmetic Operators
197
+
198
+
Standard arithmetic operations are supported.
199
+
200
+
-**Addition:**`+`
201
+
-**Subtraction:**`-`
202
+
-**Multiplication:**`*`
203
+
-**Division:**`/`
204
+
205
+
```javascript
206
+
result = 10 + 5; // 15
207
+
result = 20 - 7; // 13
208
+
result = 4 * 6; // 24
209
+
result = 100 / 10; // 10
210
+
```
211
+
212
+
#### Concatenation Operator
213
+
214
+
The `~` operator is used for string concatenation.
-**Strictly equal to:**`===` (strict comparison, checks value and type)
226
+
-**Not equal to:**`!=` (loose comparison)
227
+
-**Strictly not equal to:**`!==` (strict comparison)
228
+
-**Greater than:**`>`
229
+
-**Less than:**`<`
230
+
231
+
```javascript
232
+
isEqual = (10 == '10'); // true
233
+
isStrictlyEqual = (10 === '10'); // false
234
+
isNotEqual = (10 != 5); // true
235
+
isStrictlyNotEqual = (10 !== '10'); // true
236
+
isGreater = (20 > 10); // true
237
+
isLess = (5 < 10); // true
238
+
```
239
+
240
+
#### Unary Operators
241
+
242
+
Operators that operate on a single operand.
243
+
244
+
-**Negation:**`-` (for numbers)
245
+
-**Logical NOT:**`!` (for booleans)
246
+
247
+
```javascript
248
+
negativeNumber = -10;
249
+
isNotTrue = !true; // false
250
+
```
251
+
252
+
#### Postfix Operators
253
+
254
+
Operators that appear after their operand.
255
+
256
+
-**Increment:**`++`
257
+
-**Decrement:**`--`
258
+
259
+
```javascript
260
+
count = 0;
261
+
count++; // count is now 1
262
+
count--; // count is now 0
263
+
```
264
+
265
+
### 3. Control Flow
266
+
267
+
#### If-Else Statement
268
+
269
+
Executes a block of code if a condition is true. An optional `else` block can be provided for when the condition is false.
270
+
271
+
```javascript
272
+
// Basic if statement
273
+
if (user.hasPermission('admin')) {
274
+
echo 'Access granted!';
275
+
}
276
+
277
+
// If-else statement
278
+
if (totalLogins > 100) {
279
+
echo 'High activity!';
280
+
} else {
281
+
echo 'Normal activity.';
282
+
}
283
+
```
284
+
285
+
#### For Loop
286
+
287
+
Executes a block of code a specified number oftimes. It consists of an initializer, a condition, and an increment expression, all of which are optional.
288
+
289
+
```javascript
290
+
// Standard for loop
291
+
for (i = 0; i < 5; i++) {
292
+
echo 'Iteration: ' ~ i ~ LINEBREAK;
293
+
}
294
+
295
+
// For loop with optional parts
296
+
for (; count < 10;) { // No initializer, no increment
297
+
echo 'Count: ' ~ count ~ LINEBREAK;
298
+
count++;
299
+
}
300
+
301
+
for (;;) { // Infinite loop (use with caution, requires a break condition inside the body)
302
+
// Note: Break statement is not yet supported.
303
+
}
304
+
```
305
+
306
+
#### Foreach Loop
307
+
308
+
Iterates over elements of an array or iterable object.
309
+
310
+
```javascript
311
+
// Foreach loop over values
312
+
foreach (users_list as u) {
313
+
echo '- ' ~ u ~ LINEBREAK;
314
+
}
315
+
316
+
// Foreach loop over key-value pairs (key is optional)
317
+
foreach (users_map as key, value) {
318
+
echo key ~ ': ' ~ value ~ LINEBREAK;
319
+
}
320
+
```
321
+
322
+
### 4.Object and Array Interaction
323
+
324
+
#### Member Access
325
+
326
+
Access properties or methods of an object using the `.` operator.
327
+
328
+
```javascript
329
+
userName = user.name;
330
+
loginCount = user.logins.count();
331
+
```
332
+
333
+
#### Array Access
334
+
335
+
Access elements of an array using square brackets `[]`.
336
+
337
+
```javascript
338
+
firstUser = users_list[0];
339
+
secondUser = users_list[1];
340
+
```
341
+
342
+
#### Function Calls
343
+
344
+
Call functions or methods witharguments.
345
+
346
+
```javascript
347
+
echo 'Hello World!'; // Calling a global function (if exposed)
348
+
user.hasPermission('admin'); // Calling a method on an object
0 commit comments