Tuesday, September 24, 2024
Google search engine
HomeLanguagesArrayObject asort() Function in PHP

ArrayObject asort() Function in PHP

The asort() function of the ArrayObject class in PHP is used to sort all of the entries of the ArrayObject according to the values. The elements are arranged according to the values keeping the maintaining the association of the keys with the value.

Syntax:

void asort()  

Parameters: This function does not accepts any parameters.

Return Value: This function does not returns any value.

Below programs illustrate the above function:

Program 1:




<?php
// PHP program to illustrate the
// asort() function
  
$arr = array("a" => "neveropen", "b" => "are", "c" => "awesome");
  
$arrObject = new ArrayObject($arr);
  
// Sort the ArrayObject
$arrObject->asort();
  
print_r($arrObject);
  
?>


Output:

ArrayObject Object
(
    [storage:ArrayObject:private] => Array
        (
            [b] => are
             => awesome
            [a] => neveropen
        )

)

Program 2:




<?php
// PHP program to illustrate the
// asort() function
  
$arr = array("a" => "welcome", "b" => "to", "c" => "gfg");
  
$arrObject = new ArrayObject($arr);
  
// Sort the ArrayObject
$arrObject->asort();
  
print_r($arrObject);
  
?>


Output:

ArrayObject Object
(
    [storage:ArrayObject:private] => Array
        (
             => gfg
            [b] => to
            [a] => welcome
        )

)

Reference: http://php.net/manual/en/arrayobject.asort.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments