Read Array and Only Show Specific Value in Php

Icon

WARNING Y'all're browsing the documentation for an old version of Laravel. Consider upgrading your project to Laravel 9.10.

Helper Functions

  • Arrays
  • Paths
  • Strings
  • URLs
  • Miscellaneous

Arrays

array_add

The array_add role adds a given primal / value pair to the array if the given fundamental doesn't already be in the array.

                                              

$array = array ( ' foo ' => ' bar ' );

$array = array_add ($ array , ' key ' , ' value ' );

array_divide

The array_divide function returns two arrays, ane containing the keys, and the other containing the values of the original array.

                                              

$array = assortment ( ' foo ' => ' bar ' );

list ($ keys , $ values ) = array_divide ($ array );

array_dot

The array_dot role flattens a multi-dimensional array into a unmarried level assortment that uses "dot" annotation to betoken depth.

                                              

$array = array ( ' foo ' => array ( ' bar ' => ' baz ' ));

$assortment = array_dot ($ array );

// array('foo.bar' => 'baz');

array_except

The array_except method removes the given central / value pairs from the assortment.

                                              

$array = array_except ($ array , assortment ( ' keys ' , ' to ' , ' remove ' ));

array_fetch

The array_fetch method returns a flattened array containing the selected nested element.

                                              

$assortment = array (

assortment ( ' programmer ' => array ( ' name ' => ' Taylor ' )),

array ( ' developer ' => array ( ' name ' => ' Dayle ' )),

);

$array = array_fetch ($ assortment , ' programmer.name ' );

// array('Taylor', 'Dayle');

array_first

The array_first method returns the showtime element of an assortment passing a given truth test.

                                              

$array = array ( 100 , 200 , 300 );

$value = array_first ($ array , function ( $ central , $ value )

{

return $ value >= 150 ;

});

A default value may too be passed as the third parameter:

                                              

$value = array_first ($ assortment , $ callback , $ default );

array_last

The array_last method returns the terminal element of an array passing a given truth test.

                                              

$array = array ( 350 , 400 , 500 , 300 , 200 , 100 );

$value = array_last ($ assortment , function ( $ primal , $ value )

{

render $ value > 350 ;

});

// 500

A default value may besides be passed every bit the tertiary parameter:

                                              

$value = array_last ($ array , $ callback , $ default );

array_flatten

The array_flatten method will flatten a multi-dimensional assortment into a single level.

                                              

$array = array ( ' proper name ' => ' Joe ' , ' languages ' => array ( ' PHP ' , ' Red ' ));

$array = array_flatten ($ array );

// assortment('Joe', 'PHP', 'Ruby');

array_forget

The array_forget method volition remove a given cardinal / value pair from a deeply nested array using "dot" notation.

                                              

$assortment = array ( ' names ' => array ( ' joe ' => array ( ' programmer ' )));

array_forget ($ array , ' names.joe ' );

array_get

The array_get method will call up a given value from a deeply nested assortment using "dot" note.

                                              

$array = array ( ' names ' => assortment ( ' joe ' => array ( ' programmer ' )));

$value = array_get ($ array , ' names.joe ' );

$value = array_get ($ array , ' names.john ' , ' default ' );

Note: Want something similar array_get but for objects instead? Utilise object_get.

array_only

The array_only method volition return simply the specified fundamental / value pairs from the array.

                                              

$array = array ( ' name ' => ' Joe ' , ' historic period ' => 27 , ' votes ' => 1 );

$array = array_only ($ array , array ( ' name ' , ' votes ' ));

array_pluck

The array_pluck method volition pluck a listing of the given key / value pairs from the array.

                                              

$array = assortment ( array ( ' name ' => ' Taylor ' ), array ( ' proper noun ' => ' Dayle ' ));

$array = array_pluck ($ array , ' name ' );

// assortment('Taylor', 'Dayle');

array_pull

The array_pull method volition render a given cardinal / value pair from the assortment, besides equally remove information technology.

                                              

$assortment = array ( ' name ' => ' Taylor ' , ' age ' => 27 );

$name = array_pull ($ array , ' proper noun ' );

array_set

The array_set method will set a value inside a deeply nested assortment using "dot" annotation.

                                              

$array = array ( ' names ' => array ( ' programmer ' => ' Joe ' ));

array_set ($ assortment , ' names.editor ' , ' Taylor ' );

array_sort

The array_sort method sorts the array by the results of the given Closure.

                                              

$array = assortment (

array ( ' proper name ' => ' Jill ' ),

array ( ' name ' => ' Barry ' ),

);

$array = array_values ( array_sort ($ array , function ( $ value )

{

return $ value [ ' name ' ];

}));

array_where

Filter the array using the given Closure.

                                              

$array = array ( 100 , ' 200 ' , 300 , ' 400 ' , 500 );

$assortment = array_where ($ assortment , part ( $ key , $ value )

{

return is_string ($ value );

});

// Array ( [ane] => 200 [3] => 400 )

head

Return the first element in the array. Useful for method chaining in PHP five.3.10.

                                              

$first = caput ($ this -> returnsArray ( ' foo ' ));

last

Return the concluding element in the array. Useful for method chaining.

                                              

$concluding = last ($ this -> returnsArray ( ' foo ' ));

Paths

app_path

Get the fully qualified path to the app directory.

                                              

$path = app_path ();

base_path

Get the fully qualified path to the root of the application install.

public_path

Become the fully qualified path to the public directory.

storage_path

Go the fully qualified path to the app/storage directory.

Strings

camel_case

Convert the given string to camelCase.

                                              

$camel = camel_case ( ' foo_bar ' );

// fooBar

class_basename

Go the class proper name of the given class, without whatever namespace names.

                                              

$class = class_basename ( ' Foo\Bar\Baz ' );

// Baz

eastward

Run htmlentities over the given string, with UTF-8 back up.

                                              

$entities = e ( ' <html>foo</html> ' );

ends_with

Decide if the given haystack ends with a given needle.

                                              

$value = ends_with ( ' This is my name ' , ' name ' );

snake_case

Convert the given cord to snake_case.

                                              

$snake = snake_case ( ' fooBar ' );

// foo_bar

str_limit

Limit the number of characters in a string.

                                              

str_limit ($ value , $ limit = 100 , $ end = ' ... ' )

Case:

                                              

$value = str_limit ( ' The PHP framework for web artisans. ' , seven );

// The PHP...

starts_with

Decide if the given haystack begins with the given needle.

                                              

$value = starts_with ( ' This is my name ' , ' This ' );

str_contains

Determine if the given haystack contains the given needle.

                                              

$value = str_contains ( ' This is my name ' , ' my ' );

str_finish

Add a single instance of the given needle to the haystack. Remove any extra instances.

                                              

$cord = str_finish ( ' this/string ' , ' / ' );

// this/cord/

str_is

Determine if a given string matches a given pattern. Asterisks may be used to indicate wildcards.

                                              

$value = str_is ( ' foo* ' , ' foobar ' );

str_plural

Convert a string to its plural form (English merely).

                                              

$plural = str_plural ( ' car ' );

str_random

Generate a random string of the given length.

                                              

$string = str_random ( 40 );

str_singular

Convert a string to its atypical form (English only).

                                              

$atypical = str_singular ( ' cars ' );

studly_case

Convert the given cord to StudlyCase.

                                              

$value = studly_case ( ' foo_bar ' );

// FooBar

trans

Translate a given language line. Allonym of Lang::get.

                                              

$value = trans ( ' validation.required ' ):

trans_choice

Translate a given linguistic communication line with inflection. Alias of Lang::pick.

                                              

$value = trans_choice ( ' foo.bar ' , $ count );

URLs

action

Generate a URL for a given controller action.

                                              

$url = action ( ' [email protected] ' , $ params );

route

Generate a URL for a given named road.

                                              

$url = route ( ' routeName ' , $ params );

asset

Generate a URL for an asset.

                                              

$url = nugget ( ' img/photograph.jpg ' );

link_to

Generate a HTML link to the given URL.

                                              

echo link_to ( ' foo/bar ' , $ championship , $ attributes = array (), $ secure = null );

link_to_asset

Generate a HTML link to the given asset.

                                              

repeat link_to_asset ( ' foo/bar.zip ' , $ title , $ attributes = array (), $ secure = aught );

link_to_route

Generate a HTML link to the given route.

                                              

echo link_to_route ( ' route.name ' , $ title , $ parameters = array (), $ attributes = array ());

link_to_action

Generate a HTML link to the given controller action.

                                              

echo link_to_action ( ' [email protected] ' , $ title , $ parameters = array (), $ attributes = array ());

secure_asset

Generate a HTML link to the given asset using HTTPS.

                                              

repeat secure_asset ( ' foo/bar.cipher ' , $ title , $ attributes = assortment ());

secure_url

Generate a fully qualified URL to a given path using HTTPS.

                                              

echo secure_url ( ' foo/bar ' , $ parameters = array ());

url

Generate a fully qualified URL to the given path.

                                              

echo url ( ' foo/bar ' , $ parameters = array (), $ secure = null );

Miscellaneous

csrf_token

Get the value of the current CSRF token.

                                              

$token = csrf_token ();

dd

Dump the given variable and end execution of the script.

                                              

dd ($ value );

value

If the given value is a Closure, return the value returned by the Closure. Otherwise, return the value.

                                              

$value = value ( function () { render ' bar ' ; });

with

Return the given object. Useful for method chaining constructors in PHP five.3.x.

                                              

$value = with ( new Foo ) -> doWork ();

dotsonlasurged.blogspot.com

Source: https://laravel.com/docs/4.2/helpers

0 Response to "Read Array and Only Show Specific Value in Php"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel