Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

DEPARTMENT OF COMPUTER ENGINEERING

Subject: Web Based Application Subject Code: 22616


Development with PHP
Semester: 6th Semester Course: Computer Engineering

Laboratory No: Name of Subject Teacher: Prof. Sneha


Patange
Name of Student: Yash Dinesh Kadam Roll Id: 21203A0009

Experiment No: 4

Title of Write a PHP program for creating and manipulating: a) Indexed


Experiment array b) Associative array c) Multidimensional array

Practical related questions:


A) Write a PHP script that inserts a new item in an array in any position.
B) State the use of array_slice().

The primary use of array_slice() is to extract a specific portion (or slice) of an


array and return it as a new array. It doesn't modify the original array.

Syntax: array_slice(array $array, int $start, int $length = null, bool


$preserve_keys = false)

C) State the use of array_merge().

The main use of array_merge() is to combine two or more arrays into a single
array. It appends the elements of subsequent arrays to the end of the previous
one, resulting in a new array.

Syntax: array_merge(array $array1, array $array2, ...): array

D) What is implode and explode?

Implode():

Purpose: Joins elements of an array into a single string. It's also known as the
"join" function in some languages.

Syntax: implode(separator, array)

Parameters:
separator: A string to be inserted between each element of the array when
they're joined.
array: The array whose elements you want to join together.

Example:

Explode():
Purpose: Splits a string into an array of substrings based on a specified
delimiter.

Syntax: explode(delimiter, string)

Parameters:
delimiter: The string that marks where the original string should be split.
string: The input string to be split.

Example:

Exercise:

1. Write a PHP script to sort the following associative array:


array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40") in
a) ascending order sort by value
b) ascending order sort by Key
c) descending order sorting by Value
d) descending order sorting by Key
2. Write a PHP script which displays all the numbers between 200 and 250 that
are divisible by 4.

3. Write a PHP script to lower-case and upper-case, all elements in an array

You might also like