Tag Archives: learn php

9 Useful Php Array Functions

Hello World, In this article, we will discuss 9 Useful Php Array Functions. I will discuss some functions in some detail and with an example. Following are some steps are given below to run the array function.


print_r()

This function is used to print an array with its key and value. this function read like key automatically  0=>ram 1=>sham etc. but we can define our custom key like ram=>age ram=>DOB etc. In this, ram is key and age and DOB is its value.

<?php
$a= ['ram','sham','geeta'];
print_r ($a);
?>
//Output:
//Array ( [0] => ram [1] => sham [2] => geeta )

explode()

This function is used to convert a string into an array. we can use value and variable names to explode the string.

<?php
$a= "it is string";
print_r (explode(" ",$a));
?>
//Output: Array ( [0] => it [1] => is [2] => string )

implode()

This function is used to convert the array into a string. we can use value and variable name to implode the array.

<?php
$a= ['ram','is','a','good','boy.'];
print_r (implode(" ",$a));
?>
//Output:  ram is a good boy

sort()

This function is sort array in ascending order by its value.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
sort($name);
print_r ($name);
'</pre>';
?>
Output: 
 Array
(
    [0] => geeta
    [1] => ram
    [2] => sham
    [3] => sita
)

asort()

This function is to sort the array’s value in ascending order. In this function, the key is set according to the array’s value.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
asort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [2] => geeta
    [0] => ram
    [1] => sham
    [3] => sita
)

ksort()

This function is a short array’s key in ascending order. In this function, the value is set according to the array’s key.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
asort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [0] => ram
    [1] => sham
    [2] => geeta
    [3] => sita
)

rsort()

This function is sort array in descending order.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
sort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [0] => sita
    [1] => sham
    [2] => ram
    [3] => geeta
)

arsort()

This function is a short array’s value in descending order. In this function, the key is set according to the array’s value.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
asort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [3] => sita
    [1] => sham
    [0] => ram
    [2] => geeta
)

krsort()

This function is a short array’s key in descending order. In this function, the value is set according to the array’s key.

<?php
$name=['ram','sham','geeta','sita'];
echo '<pre>';
asort($name);
print_r ($name);
'</pre>';
?>
Output: 
Array
(
    [3] => sita
    [2] => geeta
    [1] => sham
    [0] => ram
)
create-read-update-and-delete-with-laravel

Create Read Update and delete data with Laravel 5

Hello World, Welcome to my website. This is the fourth part of the series Create project from scratch with laravel 5. In the previous part, we have discussed how to create custom admin login with laravel 5.

In this part, We will discuss how we can create read update and delete data with laravel 5. In this series, we are creating an employee management system. This part will help us to create Employee CRUD ( Create, Read, Update and Delete) with laravel. We will add, modify, view and delete employee detail in this part. I have divided this tutorial into the following parts.

Continue reading

create-project-from-scratch-with-laravel

Setup laravel 5 on local system and create hello world app

Hello World, Welcome to my website. This is the second part of the series Create project from scratch with laravel 5. In the first part of this series, we have discussed about the project and technologies which we are using in this series. In this part, we will setup laravel 5 on local system and create hello world app.

Continue reading

create-project-from-scratch-with-laravel

Create project from scratch with laravel 5

Hello World, welcome to my website. Today i am going to create a tutorial series of laravel 5. In this series, we will create a project from scratch. I have divided this series in following parts.

Continue reading

Generate Dummy data in laravel 5

Hello World, Welcome to this website. Today we will discuss how to generate dummy data in laravel 5 with faker class. Generating dummy data with the automatic process will definitely increase our productivity.

Here you will not learn just about generating dummy data but you will also learn the following things: Continue reading

Upload Image in Laravel 5

Hello world, this tutorial is about how to upload image in laravel 5. In this tutorial, we will create simple example with upload image in folder and then save that image in database table. I have divided this tutorial in following parts:

  • Setup laravel 5 on xampp server
  • Setup controller, view and route
  • Upload image in folder
  • Setup database, model and migration
  • Save image in database table

Continue reading