I try to get a number of elements in an array, using dynamic array name.
I need the array name to be dynamic.
The array name is constructed as 'inf_ln_$nmb', where $nmb is a file line number
So, say I have the arr 'inf_ln_4':
I do next:
Is there a way to prevent the bash-shell from treat the '$a[0]' as a substitution?
My main attempt is to copy the current dynamicaly numbered array to some staticly-named array to comfortably work with it's element
Hi,
Can anyone advise me on how to use array on Bash? I am really confuse in how eval is link to array... What i wan to do is let say i have an index of an array of 50. Store either 'N' or 'Y' or "NA" in each index. how to i go about doing it.. then lastly how to i print all the values out in... (2 Replies)
I want to get a status code array for the commands in eval.
For example,
eval "ls abc; ls def; ls $HOME"
I want to get the status code for each ls command in eval. Is there any way to make it?
Thanks. (2 Replies)
Hi,
My doubt is how to access array elements..
Situation is as below:
#!/bin/ksh
set -x
typeset -i x=0
typeset -i y=0
typeset -i BID=0
typeset -i count=0
while ] ; do
x=`expr $x + 1`;
hwmgr show scsi > scsi.tmp
while read line; do
set... (1 Reply)
Hi.
I am trying to populate an array using eval in the background within a function. So this function will create a list of 3 character directories from SVN and store in an array. I want to call this function when the script starts in the background unknown to the user.
The problem is that... (2 Replies)
Is there a way to print multiple array elements without iterating through the array using bash?
Can you do something like...
echo ${array}and get all those separate elements from the array? (2 Replies)
I have a script which takes backup of some configuration files on my server. It does that by using an array which contains the complete path to the files to backup.
It copys the files to a pre defined dir. Each "program" has it's own folder, ex. apache.conf is being copied to /predefined... (7 Replies)
Hi everyone, :)
I'm trying to make a simple C program that scans an array of chars to see if its elements are similar.
I can't understand what's wrong. Could you help me to fix this? Here is the code.
Thanks!
#include<stdio.h>
int main() {
int arr;
int i, len;
int flag =... (10 Replies)
Hi All,
need help with reading the array and sum of the array elements.
given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large.
Input Format
The first line of the input consists of an... (1 Reply)
I have an array code and output is below:
echo $1
while read -r fline; do
echo "%%%%%%$fline%%%%%"
fmy_array+=("$fline")
done <<< "$1"
Output:
CR30903 YU0007 SRIL CR30903 Yogesh SRIL
%%%%%%CR30903 YU0007 SRIL%%%%%
%%%%%%CR30903 Yogesh SRIL%%%%%
... (8 Replies)
Discussion started by: mohtashims
8 Replies
LEARN ABOUT PHP
array_filter
ARRAY_FILTER(3) 1 ARRAY_FILTER(3)array_filter - Filters elements of an array using a callback functionSYNOPSIS
array array_filter (array $array, [callable $callback], [int $flag])
DESCRIPTION
Iterates over each value in the $array passing them to the $callback function. If the $callback function returns true, the current value
from $array is returned into the result array. Array keys are preserved.
PARAMETERS
o $array
- The array to iterate over
o $callback
- The callback function to use If no $callback is supplied, all entries of $array equal to FALSE (see converting to boolean) will
be removed.
o $flag
- Flag determining what arguments are sent to $callback:
o ARRAY_FILTER_USE_KEY - pass key as the only argument to $callback instead of the value
o ARRAY_FILTER_USE_BOTH - pass both value and key as arguments to $callback instead of the value
RETURN VALUES
Returns the filtered array.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.6.0 | |
| | |
| | Added optional $flag parameter and constants |
| | ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
array_filter(3) example
<?php
function odd($var)
{
// returns whether the input integer is odd
return($var & 1);
}
function even($var)
{
// returns whether the input integer is even
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 :
";
print_r(array_filter($array1, "odd"));
echo "Even:
";
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 #2
array_filter(3) without $callback
<?php
$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
)
Example #3
array_filter(3) with $flag
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
var_dump(array_filter($arr, function($k) {
return $k == 'b';
}, ARRAY_FILTER_USE_KEY));
var_dump(array_filter($arr, function($v, $k) {
return $k == 'b' || $v == 4;
}, ARRAY_FILTER_USE_BOTH));
?>
The above example will output:
array(1) {
["b"]=>
int(2)
}
array(2) {
["b"]=>
int(2)
["d"]=>
int(4)
}
NOTES
Caution
If the array is changed from the callback function (e.g. element added, deleted or unset) the behavior of this function is unde-
fined.
SEE ALSO array_map(3), array_reduce(3), array_walk(3).
PHP Documentation Group ARRAY_FILTER(3)