PHP Code Reviewer
PHP Code Reviewer
include ‘filename’;
Examples:
include ‘connection.php’;
require ‘connect.inc.php’;
require_once ‘connect.inc.php’;
PHP ARRAY
Examples:
array_pop($students);
Example:
Answer:
array_splice($students, 1, 1);
//The array now is $students = [“mia”, “Lexi”, 69];
The first parameter is $students, this is the array that you want to delete the item.
The second parameter is 1, this the index that you want to delete. “Jhonny” is the
second item and it’s index is 1.
The third parameter is 1, this is the length of items that you want to delete. If you want
to delete two items, replace this with 2.
Here’s another example, but this time we will delete 2 items in the array.
Answer:
array_splice($students, 2, 2);
$students – is the array this is the array that you want to delete the item.
2 – is the index that I want to delete, because it is the third item in the array.
2 – is the length of items that I want to delete, because I want to delete 2 items; but If
you want to delete three items. Then replace it with 3.
ADDING ITEMS IN THE ARRAY
Syntax:
Example:
//The array now is $students = [“mia”, “Jhonny”, “Lexi”, 69, “Aj Raval”];
//The array now is $students = [“mia”, “Jhonny”, “Lexi”, 69, “Aj Raval”, “Ivani”, “Melai”);];
ACCESSING ITEMS IN ARRAY
Accessing items in the array differs depending on the type of array: Indexed and Associative.
// output: Jhonny
2. Associative Array - Associative arrays are arrays that use named keys that you assign to them.
// output: 29
ACCESSING ITEMS IN MULTI DIMENSIONAL ARRAY
$students = [
[“Jorgi”, “Jhonny”];
];
];
$students = [
];
1. Using foreach()
foreach($array_variable as $new_variable){
echo $new_variable;
foreach($students as $student){
foreach($students as $pornstars){
//output:
Mia
Jhonny
Lexi
69
You can add all the items in an array using the array_sum().
echo array_sum($age);
print_r($combine_age);
// output: $combine_age = [50, 20, 36, 69, 24, 70, 16, 9];