php - array_map

Description

array array_map ( callback $callback, array $arr1 [, array $...] )
array_map() returns an array containing all the elements of arr1 after applying the callback function to each one. The number of parameters that the callback function accepts should match the number of arrays passed to the array_map()

Parameters


callback
Callback function to run for each element in each array.
arr1
An array to run through the callback function.
array
Variable list of array arguments to run through the callback function.

Return Values

Returns an array containing all the elements of arr1 after applying the callback function to each one.

Examples

Example 252. array_map() example
<?phpfunction cube($n)
{
return(
$n * $n * $n);
}
$a = array(1, 2, 3, 4, 5);$b = array_map("cube", $a);print_r($b);?>
This makes $b have:
Array
(
    [0] => 1
    [1] => 8
    [2] => 27
    [3] => 64
    [4] => 125
)

Examples


Example 253. array_map() - using more arrays

function show_Spanish($n, $m)
{
return(
"The number $n is called $m in Spanish");
}

function
map_Spanish($n, $m)
{
return(array(
$n => $m));
}
$a = array(1, 2, 3, 4, 5);$b = array("uno", "dos", "tres", "cuatro", "cinco");
$c = array_map("show_Spanish", $a, $b);print_r($c);
$d = array_map("map_Spanish", $a , $b);print_r($d);
The above example will output:
// printout of $c
Array
(
   [0] => The number 1 is called uno in Spanish
   [1] => The number 2 is called dos in Spanish
   [2] => The number 3 is called tres in Spanish
   [3] => The number 4 is called cuatro in Spanish
   [4] => The number 5 is called cinco in Spanish
)

// printout of $d
Array
(
   [0] => Array
        (
           [1] => uno
        )

   [1] => Array
        (
           [2] => dos
        )

   [2] => Array
        (
           [3] => tres
        )

   [3] => Array
        (
           [4] => cuatro
        )

   [4] => Array
        (
           [5] => cinco
        )

)    

Usually when using two or more arrays, they should be of equal length because the callback function is applied in parallel to the corresponding elements. If the arrays are of unequal length, the shortest one will be extended with empty elements.
An interesting use of this function is to construct an array of arrays, which can be easily performed by using NULL as the name of the callback function

Example 254. Creating an array of arrays

$a
= array(1, 2, 3, 4, 5);$b = array("one", "two", "three", "four", "five");$c = array("uno", "dos", "tres", "cuatro", "cinco");
$d = array_map(null, $a, $b, $c);print_r($d);
The above example will output:
Array
(
   [0] => Array
        (
           [0] => 1
           [1] => one
           [2] => uno
        )

   [1] => Array
        (
           [0] => 2
           [1] => two
           [2] => dos
       )

   [2] => Array
        (
           [0] => 3
           [1] => three
           [2] => tres
        )

   [3] => Array
        (
           [0] => 4
           [1] => four
           [2] => cuatro
        )

   [4] => Array
        (
           [0] => 5
           [1] => five
           [2] => cinco
        )

)

php - array_keys

Description

array array_keys ( array $input [, mixed $search_value [, bool $strict]] )
array_keys() returns the keys, numeric and string, from the input array.
If the optional search_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the input are returned. As of PHP 5, you can use strict parameter for comparison including type (===).

Parameters



input
An array containing keys to return.
search_value
If specified, then only keys containing these values are returned.
strict
As of PHP 5, this parameter determines if strict comparision (===) should be used during the search.

Return Values

Returns an array of all the keys in input.

Examples


Example 251. array_keys() example

$array
= array(0 => 100, "color" => "red");print_r(array_keys($array));
$array = array("blue", "red", "green", "blue", "blue");print_r(array_keys($array, "blue"));
$array = array("color" => array("blue", "red", "green"),
"size" => array("small", "medium", "large"));print_r(array_keys($array));
The above example will output:
Array
(
   [0] => 0
   [1] => color
)
Array
(
   [0] => 0
   [1] => 3
   [2] => 4
)
Array
(
   [0] => color
   [1] => size
)

php - array_key_exists

Description

bool array_key_exists ( mixed $key, array $search )
array_key_exists() returns TRUE if the given key is set in the array. key can be any value possible for an array index. array_key_exists() also works on objects.

Parameters



key
Value to check.
search
An array with keys to check.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 249. array_key_exists() example

$search_array
= array('first' => 1, 'second' => 4);
if (
array_key_exists('first', $search_array)) {
echo
"The 'first' element is in the array";
}
Note: The name of this function is key_exists() in PHP 4.0.6.
Example 250. array_key_exists() vs isset()
isset() does not return TRUE for array keys that correspond to a NULL value, while array_key_exists() does.
 
$search_array = array('first' => null, 'second' => 4);
// returns falseisset($search_array['first']);
// returns truearray_key_exists('first', $search_array);

php - array_intersect_ukey

Description

array array_intersect_ukey ( array $array1, array $array2 [, array $..., callback $key_compare_func] )
array_intersect_ukey() returns an array containing all the values of array1 which have matching keys that are present in all the arguments.
This comparison is done by a user supplied callback function. It must return an integer less than, equal to, or greater than zero if the first key is considered to be respectively less than, equal to, or greater than the second.

Parameters



array1
Initial array for comparision of the arrays.
array2
First array to compare keys against.
array
Variable list of array arguments to compare keys against.
key_compare_func
User supplied callback function to do the comparision.

Return Values

Returns the values of array1 whose keys exist in all the arguments.

Examples


Example 247. array_intersect_ukey() example

function key_compare_func($key1, $key2)
{
if (
$key1 == $key2)
return
0;
else if (
$key1 > $key2)
return
1;
else
return -
1;
}
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
var_dump(array_intersect_ukey($array1, $array2, 'key_compare_func'));

The above example will output:
array(2) {
["blue"]=>  int(1)
  ["green"]=> int(3)
}    

In our example you see that only the keys 'blue' and 'green' are present in both arrays and thus returned. Also notice that the values for the keys 'blue' and 'green' differ between the two arrays. A match still occurs because only the keys are checked. The values returned are those of array1.

php - array_intersect_uassoc

Description

array array_intersect_uassoc ( array $array1, array $array2 [, array $ ..., callback $key_compare_func] )
array_intersect_uassoc() returns an array containing all the values of array1 that are present in all the arguments. Note that the keys are used in the comparison unlike in array_intersect().
The index comparison is done by a user supplied callback function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Parameters



array1
Initial array for comparision of the arrays.
array2
First array to compare keys against.
array
Variable list of array arguments to compare values against.
key_compare_func
User supplied callback function to do the comparision.

Return Values

Returns the values of array1 whose values exist in all of the arguments.

Examples


Example 246. array_intersect_uassoc() example

$array1
= array("a" => "green", "b" => "brown", "c" => "blue", "red");$array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red");
print_r(array_intersect_uassoc($array1, $array2, "strcasecmp"));
The above example will output:
Array
(
[b] => brown
)

php - array_intersect_key

Description

array array_intersect_key ( array $array1, array $array2 [, array $ ...] )
array_intersect_key() returns an array containing all the values of array1 which have matching keys that are present in all the arguments.

Parameters



array1
The array with master keys to check.
array2
An array to compare keys against.
array
A variable list of arrays to compare.

Return Values

Returns an associative array containing all the values of array1 which have matching keys that are present in all arguments.

Examples


Example 245. array_intersect_key() example

$array1
= array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
var_dump(array_intersect_key($array1, $array2));

The above example will output:
array(2) {
["blue"]=>
  int(1)
["green"]=>
  int(3)
}

    

In our example you see that only the keys 'blue' and 'green' are present in both arrays and thus returned. Also notice that the values for the keys 'blue' and 'green' differ between the two arrays. A match still occurs because only the keys are checked. The values returned are those of array1.
The two keys from the key => value pairs are considered equal only if (string) $key1 === (string) $key2 . In other words a strict type check is executed so the string representation must be the same.

php - array_intersect_assoc

Description

array array_intersect_assoc ( array $array1, array $array2 [, array $ ...] )
array_intersect_assoc() returns an array containing all the values of array1 that are present in all the arguments. Note that the keys are used in the comparison unlike in array_intersect().

Parameters



array1
The array with master values to check.
array2
An array to compare values against.
array
A variable list of arrays to compare.

Return Values

Returns an associative array containing all the values in array1 that are present in all of the arguments.

Examples


Example 244. array_intersect_assoc() example

$array1
= array("a" => "green", "b" => "brown", "c" => "blue", "red");$array2 = array("a" => "green", "yellow", "red");$result_array = array_intersect_assoc($array1, $array2);print_r($result_array);
The above example will output:
Array(
[a] => green
)

    

In our example you see that only the pair "a" => "green" is present in both arrays and thus is returned. The value "red" is not returned because in $array1 its key is 0 while the key of "red" in $array2 is 1.
The two values from the key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict type check is executed so the string representation must be the same.

php - array_intersect

Description

array array_intersect ( array $array1, array $array2 [, array $ ...] )
array_intersect() returns an array containing all the values of array1 that are present in all the arguments. Note that keys are preserved.

Parameters



array1
The array with master values to check.
array2
An array to compare values against.
array
A variable list of arrays to compare.

Return Values

Returns an array containing all of the values in array1 whose values exist in all of the parameters.

Examples


Example 248. array_intersect() example

$array1
= array("a" => "green", "red", "blue");$array2 = array("b" => "green", "yellow", "red");$result = array_intersect($array1, $array2);print_r($result);
The above example will output:
Array(
  [a] => green
  [0] => red
)

php - array_flip

Description

array array_flip ( array $trans )
array_flip() returns an array in flip order, i.e. keys from trans become values and values from trans become keys.
Note that the values of trans need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be flipped.
If a value has several occurrences, the latest key will be used as its values, and all others will be lost.

Parameters



trans
An array of key/value pairs to be flipped.

Return Values

Returns the flipped array on success and FALSE on failure.

Examples


Example 242. array_flip() example

$trans
= array_flip($trans);$original = strtr($str, $trans);


Example 243. array_flip() example : collision

$trans
= array("a" => 1, "b" => 1, "c" => 2);$trans = array_flip($trans);print_r($trans);

now $trans is:
Array(
[1] => b
 [2] => c
)

php - array_filter

Description

array array_filter ( array $input [, callback $callback] )
Iterates over each value in the input array passing them to the callback function. If the callback function returns true, the current value from input is returned into the result array. Array keys are preserved.

Parameters



input
The array to iterate over
callback
The callback function to use If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed.

Return Values

Returns the filtered array.

Examples


Example 240. array_filter() example

function odd($var)
{
return(
$var & 1);
}

function
even($var)
{
return(!(
$var & 1));
}
$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);$array2 = array(6, 7, 8, 9, 10, 11, 12);

echo
"Odd :\n";print_r(array_filter($array1, "odd"));
echo
"Even:\n";print_r(array_filter($array2, "even"));

The above example will output:
Odd :
Array(
  [a] => 1
  [c] => 3
  [e] => 5
)
Even:
Array(
  [0] => 6
  [2] => 8
  [4] => 10
  [6] => 12
)

Example 241. array_filter() without callback

$entry
= array(
0 => 'foo',
1 => false,
2 => -1,
3 => null,
4 => ''
);
print_r(array_filter($entry));
The above example will output:
Array(
[0] => foo
 [2] => -1
)

php - array_fill

Description

array array_fill ( int $start_index, int $num, mixed $value )

Fills an array with num entries of the value of the value parameter, keys starting at the start_index parameter.

Parameters


start_index

The first index of the returned array

num

Number of elements to insert

value

Values to use filling

Return Values

Returns the filled array

Errors/Exceptions

Throws a E_WARNING if num is less than one.

Examples

Example 239. array_fill() example

$a = array_fill(5, 6, 'banana');
print_r($a);

The above example will output:

Array (
[5]  => banana
[6]  => banana
[7]  => banana
[8]  => banana
[9]  => banana
[10] => banana ) 

php - array_diff_ukey

Description

array array_diff_ukey ( array $array1, array $array2 [, array $ ..., callback $key_compare_func] )

Compares the keys from array1 against the keys from array2 and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.

Unlike array_diff_key() an user supplied callback function is used for the indices comparision, not internal function.

Parameters


array1

The array to compare from

array2

An array to compare against

...

More arrays to compare against

key_compare_func

callback function to use. The callback function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Return Values

Returns an array containing all the entries from array1 that are not present in any of the other arrays.

Examples

Example 236. array_diff_ukey() example

function key_compare_func($key1, $key2)
{
if (
$key1 == $key2)
return
0;
else if (
$key1 > $key2)
return
1;
else
return -
1;
}

$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);

var_dump(array_diff_ukey($array1, $array2, 'key_compare_func'));
?>

The above example will output:

array(2) {  
["red"]=>   int(2)  
["purple"]=>   int(4)
} 

php - array_diff_uassoc

Description

array array_diff_uassoc ( array $array1, array $array2 [, array $..., callback $key_compare_func] )

Compares array1 against array2 and returns the difference. Unlike array_diff() the array keys are used in the comparision.

Unlike array_diff_assoc() an user supplied callback function is used for the indices comparision, not internal function.

Parameters


array1

The array to compare from

array2

An array to compare against

...

More arrays to compare against

key_compare_func

callback function to use. The callback function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Return Values

Returns an array containing all the entries from array1 that are not present in any of the other arrays.

Examples

Example 235. array_diff_uassoc() example

The "a" => "green" pair is present in both arrays and thus it is not in the ouput from the function. Unlike this, the pair 0 => "red" is in the ouput because in the second argument "red" has key which is 1.

function key_compare_func($a, $b)
{
if (
$a === $b) {
return
0;
}
return (
$a > $b)? 1:-1;
}

$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$result = array_diff_uassoc($array1, $array2, "key_compare_func");
print_r($result);

The above example will output:

Array (    
[b] => brown    
[c] => blue    
[0] => red
)      

The equality of 2 indices is checked by the user supplied callback function.

php - array_diff_key

Description

array array_diff_key ( array $array1, array $array2 [, array $...] )

Compares the keys from array1 against the keys from array2 and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.

Parameters


array1

The array to compare from

array2

An array to compare against

...

More arrays to compare against

Return Values

Returns an array containing all the entries from array1 that are not present in any of the other arrays.

Examples

Example 234. array_diff_key() example

The two keys from the key => value pairs are considered equal only if (string) $key1 === (string) $key2 . In other words a strict type check is executed so the string representation must be the same.

$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);

var_dump(array_diff_key($array1, $array2));

The above example will output:

array(2) {  
["red"]=>   int(2)  
["purple"]=>   int(4)
} 

php - array_diff_assoc

Description

array array_diff_assoc ( array $array1, array $array2 [, array $...] )

Compares array1 against array2 and returns the difference. Unlike array_diff() the array keys are used in the comparision.

Parameters


array1

The array to compare from

array2

An array to compare against

...

More arrays to compare against

Return Values

Returns an array containing all the values from array1 that are not present in any of the other arrays.

Examples

Example 232. array_diff_assoc() example

In this example you see the "a" => "green" pair is present in both arrays and thus it is not in the ouput from the function. Unlike this, the pair 0 => "red" is in the ouput because in the second argument "red" has key which is 1.

$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$result = array_diff_assoc($array1, $array2);
print_r($result);

The above example will output:

Array (    
[b] => brown    
[c] => blue    
[0] => red
)      

Example 233. array_diff_assoc() example

Two values from key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict check takes place so the string representations must be the same.

$array1 = array(0, 1, 2);
$array2 = array("00", "01", "2");
$result = array_diff_assoc($array1, $array2);
print_r($result);

The above example will output:

Array
(
[0] => 0
[1] => 1
) 

php - array_diff

Description

array array_diff ( array $array1, array $array2 [, array $ ...] )

Compares array1 against array2 and returns the difference.

Examples

Example 237. array_diff() example

= array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);

print_r($result);
?>

Multiple occurrences in $array1 are all treated the same way. This will output :

Array
(
[1] => blue
) 

php - array_count_values

Description

array array_count_values ( array $input )

array_count_values() returns an array using the values of the input array as keys and their frequency in input as values.

Parameters


input

The array of values to count

Return Values

Returns an assosiative array of values from input as keys and their count as value.

Errors/Exceptions

Throws E_WARNING for every element which is not string or integer.

Examples

Example 231. array_count_values() example

= array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));
?>

The above example will output:

Array (    
[1] => 2    
[hello] => 2    
[world] => 1
) 

php - array_combine

Description

array array_combine ( array $keys, array $values )

Creates an array by using the values from the keys array as keys and the values from the values array as the corresponding values.

Parameters


keys

Array of keys to be used

values

Array of values to be used

Return Values

Returns the combined array, FALSE if the number of elements for each array isn't equal or if the arrays are empty.

Errors/Exceptions

Throws E_WARNING if keys and values are either empty or the number of elements does not match.

Examples

Example 230. A simple array_combine() example

$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);

print_r($c);

The above example will output:

Array (    
[green]  => avocado    
[red]    => apple    
[yellow] => banana
) 

php - array_chunk

Description

array array_chunk ( array $input, int $size [, bool $preserve_keys] )

Chunks an array into size large chunks. The last chunk may contain less than size elements.

Parameters


input

The array to work on

size

The size of each chunk

preserve_keys

When set to TRUE keys will be preserved. Default is FALSE which will reindex the chunk numerically

Return Values

Returns a multidimensional numerically indexed array, starting with zero, with each dimension containing size elements.

Errors/Exceptions

If size is less than 1 E_WARNING will be thrown and NULL returned.

Examples

Example 229. array_chunk() example

$input_array = array('a', 'b', 'c', 'd', 'e');
print_r(array_chunk($input_array, 2));
print_r(array_chunk($input_array, 2, true));

The above example will output:

Array (    
[0] => Array(            
[0] => a            
[1] => b        
)     
[1] => Array(            
[0] => c            
[1] => d        
)     
[2] => Array(
[0] => e        
) 
)
Array (    
[0] => Array(            
[0] => a            
[1] => b        
)     
[1] => Array(            
[2] => c            
[3] => d        
)     
[2] => Array(            
[4] => e        
) 
) 

php - array_change_key_case

Description

array array_change_key_case ( array $input [, int $case] )

Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.

Parameters


input

The array to work on

case

Either CASE_UPPER or CASE_LOWER (default)

Return Values

Returns an array with its keys lower or uppercased, or false if input is not an array.

Errors/Exceptions

Throws E_WARNING if input is not an array.

Examples

Example 228. array_change_key_case() example

$input_array = array("FirSt" => 1, "SecOnd" => 4);
print_r(array_change_key_case($input_array, CASE_UPPER));

The above example will output:

Array (    
[FIRST] => 1    
[SECOND] => 4
) 

php - Array Operators

Table 15.8. Array Operators

Example Name Result
$a + $b Union Union of $a and $b.
$a == $b Equality TRUE if $a and $b have the same key/value pairs.
$a === $b Identity TRUE if $a and $b have the same key/value pairs in the same order and of the same types.
$a != $b Inequality TRUE if $a is not equal to $b.
$a <> $b Inequality TRUE if $a is not equal to $b.
$a !== $b Non-identity TRUE if $a is not identical to $b.

The + operator appends elements of remaining keys from the right handed array to the left handed, whereas duplicated keys are NOT overwritten.

$a = array("a" => "apple", "b" => "banana");
$b = array("a" => "pear", "b" => "strawberry", "c" => "cherry");

$c = $a + $b; // Union of $a and $b
echo "Union of \$a and \$b: \n";
var_dump($c);

$c = $b + $a; // Union of $b and $a
echo "Union of \$b and \$a: \n";
var_dump($c);

When executed, this script will print the following: Union of $a and $b:
array(3) {
["a"]=>
string(5) "apple"
["b"]=>
string(6) "banana"
["c"]=>
string(6) "cherry"
}
Union of $b and $a:
array(3) {
["a"]=>
string(4) "pear"
["b"]=>
string(10) "strawberry"
["c"]=>
string(6) "cherry"
}

Elements of arrays are equal for the comparison if they have the same key and value.

Example 15.7. Comparing arrays

$a = array("apple", "banana");
$b = array(1 => "banana", "0" => "apple");

var_dump($a == $b); // bool(true)
var_dump($a === $b); // bool(false)

php - array

Description

array array ( [mixed $...] )

Returns an array of the parameters. The parameters can be given an index with the => operator. Read the section on the array type for more information on what an array is.

Note: array() is a language construct used to represent literal arrays, and not a regular function.

Syntax "index => values", separated by commas, define index and values. index may be of type string or integer. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first.

Having a trailing comma after the last defined array entry, while unusual, is a valid syntax.

The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays.

Example 287. array() example

$fruits = array (
"fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "third")
);

Example 288. Automatic index with array()

$array
= array(1, 1, 1, 1, 1, 8 => 1, 4 => 1, 19, 3 => 13);
print_r($array);

The above example will output:Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 13
[4] => 1
[8] => 1
[9] => 19
)

Note that index '3' is defined twice, and keep its final value of 13. Index 4 is defined after index 8, and next generated index (value 19) is 9, since biggest index was 8.

This example creates a 1-based array.

Example 289. 1-based index with array()

$firstquarter = array(1 => 'January', 'February', 'March');
print_r($firstquarter);

The above example will output:
Array (    
[1] => January    
[2] => February    
[3] => March
)      

As in Perl, you can access a value from the array inside double quotes. However, with PHP you'll need to enclose your array between curly braces.

Example 290. Accessing an array inside double quotes

$foo = array('bar' => 'baz');
echo
"Hello {$foo['bar']}!"; // Hello baz!

php - apd_set_socket_session_trace

Description

bool apd_set_socket_session_trace ( string $tcp_server, int $socket_type, int $port, int $debug_level )

Connects to the specified tcp_server (eg. tcplisten) and sends debugging data to the socket.

Parameters


tcp_server

IP or Unix Domain socket (like a file) of the TCP server.

socket_type

Can be AF_UNIX for file based sockets or APD_AF_INET for standard tcp/ip.

port

You can use any port, but higher numbers are better as most of the lower numbers may be used by other system services.

debug_level

An integer which is formed by adding together the XXX_TRACE constants.

It is not recommended to use MEMORY_TRACE. It is very slow and does not appear to be accurate. ASSIGNMENT_TRACE is not implemented yet.

To turn on all functional traces (TIMING, FUNCTIONS, ARGS SUMMARY (like strace -c)) use the value 99

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example 225. apd_set_socket_session_trace() example

apd_set_socket_session_trace("127.0.0.1",APD_AF_INET,7112,0);

php - apd_set_session_trace

Description

void apd_set_session_trace ( int $debug_level [, string $dump_directory] )

Starts debugging to apd_dump_{process_id} in the dump directory.

Parameters


debug_level

An integer which is formed by adding together the XXX_TRACE constants.

It is not recommended to use MEMORY_TRACE. It is very slow and does not appear to be accurate. ASSIGNMENT_TRACE is not implemented yet.

To turn on all functional traces (TIMING, FUNCTIONS, ARGS SUMMARY (like strace -c)) use the value 99

dump_directory

The directory in which the profile dump file is written. If not set, the apd.dumpdir setting from the php.ini file is used.

Return Values

No value is returned.

Examples

Example 223. apd_set_session_trace() example

apd_set_session_trace(99);

php - apd_set_pprof_trace

Description

string apd_set_pprof_trace ( [string $dump_directory [, string $fragment]] )

Starts debugging to pprof_{process_id} in the dump directory.

Parameters


dump_directory

The directory in which the profile dump file is written. If not set, the apd.dumpdir setting from the php.ini file is used.

fragment

Return Values

Returns path of the destination file.

Examples

Example 222. apd_set_pprof_trace() example

apd_set_pprof_trace();

php - apd_set_session

Description

void apd_set_session ( int $debug_level )

This can be used to increase or decrease debugging in a different area of your application.

Parameters


debug_level

An integer which is formed by adding together the XXX_TRACE constants.

It is not recommended to use MEMORY_TRACE. It is very slow and does not appear to be accurate. ASSIGNMENT_TRACE is not implemented yet.

To turn on all functional traces (TIMING, FUNCTIONS, ARGS SUMMARY (like strace -c)) use the value 99

Return Values

No value is returned.

Examples

Example 224. apd_set_session() example

apd_set_session(9);

php - apd_echo

Description

bool apd_echo ( string $output )

Usually sent via the socket to request information about the running script.

Parameters


output

The debugged variable.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example 220. apd_echo() example

apd_echo($i);