Im trying to get all the 4 digit numbers from this website, However there are some numbers that are less than 4 digits for example #20 in the array is value 20.
Array ( [0] => 6280 [1] => 6279 [2] => 6278 [3] => 6277 [4] => 6276 [5] => 6275 [6] => 6274 [7] => 6273 [8] => 6272 [9] => 6271 [10] => 6270 [11] => 6269 [12] => 6268 [13] => 6267 [14] => 6266 [15] => 6265 [16] => 6264 [17] => 6263 [18] => 6262 [19] => 6261 [20] => 20 [21] => 6320 )
This is the script im using:
$pattern = '#<b>([0-9]+)</b>#';
preg_match_all($pattern,$website,$match_number);
Is it possible to only get it if there are 4 digits no less no more.
Thanks
Change the pattern to:
$pattern = '#<b>([0-9]{4})</b>#';
Related
I need to split Unicode text to array, keeping spacing and punctuation.Problem: I need to face abreviations like "That's" or "'till" as a single term.
What I came got far:
$String = "'till I got this help, I could not do by myself!";
$arr = preg_split("/(\s|\W)/u", $String, -1, PREG_SPLIT_DELIM_CAPTURE |PREG_SPLIT_NO_EMPTY);
foreach ($arr as $word){
echo "<span class=\"Term $word\">".$word."</span>";
}
[0] => '
[1] => till
[2] =>
[3] => I
[4] =>
[5] => got
[6] =>
[7] => this
[8] =>
[9] => help
[10] => ,
[11] =>
[12] => I
[13] =>
[14] => could
[15] =>
[16] => not
[17] =>
[18] => do
[19] =>
[20] => by
[21] =>
[22] => myself
[23] => !
)
i have following array format in php:
Array
(
[item] => Array
(
[0] => RSJ Pole 116 x100 ,11 Mtr
[1] => RSJ Pole 116 x100 ,10 Mtr
[2] => RSJ Pole 116 x 100, 9 Mtr
[3] => RSJ Pole 116 x 100, 8 Mtr
[4] => Line Length in Kms
[5] => RSJ 125x70, 9 m long
[6] => PSC Pole 9 Mtr
[7] => PSC Pole 8 Mtr
[8] => Conductor ACSR Dog 0.1
[9] => Conductor ACSR Rabbit 55 Sq.mm
[10] => Conductor ACSR Raccon 80 Sq.mm
[11] => Conductor Weisel 34 Sq.mm
[12] => Conductor Ant
[13] => Conductor Gnat
[14] => New DTC 100 KVA
[15] => New DTC 63 KVA
[16] => BPL Connection
[17] => SDT
)
[scope] => Array
(
[0] => 1172
[1] => 6637
[2] => 854
[3] => 4
[4] => 653.71
[5] => 558.9
[6] => 5864
[7] => 820
[8] => 745385
[9] => 1188772.2
[10] => 327600
[11] => 18900
[12] => 232015.9
[13] => 70634.3
[14] => 344
[15] => 54
[16] => 13632
[17] => 37
)
[till] => Array
(
[0] => 3
[1] => 4
[2] => 4
[3] => 6
[4] => 5
[5] => 5
[6] => 5
[7] => 5
[8] => 2
[9] => 5
[10] => 5
[11] => 5
[12] => 5
[13] => 5
[14] => 5
[15] => 5
[16] => 5
[17] => 2
)
[value] => Array
(
[0] => 4
[1] => 7
[2] => 1
[3] => 2
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
)
[submit] => submit
)
i want to concatenate with "_" operator before submitting or while inserting into database field for eg. 1172_3_4
You can array_map the 3 arrays
$arr = .... //Your array here
$results = array_map(function($s, $t, $v) {
return $s . "_" . $t . "_" . $v;
}, $arr['scope'], $arr['till'], $arr['value']);
echo "<pre>";
print_r( $results );
echo "</pre>";
$results will have the value:
Array
(
[0] => 1172_3_4
[1] => 6637_4_7
[2] => 854_4_1
[3] => 4_6_2
[4] => 653.71_5_
[5] => 558.9_5_
[6] => 5864_5_
[7] => 820_5_
[8] => 745385_2_
[9] => 1188772.2_5_
[10] => 327600_5_
[11] => 18900_5_
[12] => 232015.9_5_
[13] => 70634.3_5_
[14] => 344_5_
[15] => 54_5_
[16] => 13632_5_
[17] => 37_2_
)
Doc: array_map()
Implement the loop at main array and increment in $i then concatenate $array_variable['scope'][$i].'_'.$array_variable['till'][$i].'_'.$array_variable['value'][$i].
Hi I have a collection of numbers and I want to find the most occurring number and then the 2nd most occurring and then the third most occurring till 10 and store the result in a array.
The collection looks like this
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => 12
[1] => 194
[2] => 241
[3] => 4
[4] => 29
[5] => 4
[6] => 12
[7] => 15
[8] => 21
[9] => 31
[10] => 281
[11] => 4
[12] => 6
[13] => 4
[14] => 2
[15] => 6
[16] => 4
[17] => 4
[18] => 4
[19] => 15
[20] => 4
[21] => 4
[22] => 13
[23] => 10
[24] => 8
[25] => 8
[26] => 2
[27] => 2
[28] => 2
[29] => 17
[30] => 4
[31] => 20
[32] => 2
[33] => 4
[34] => 20
[35] => 6
)
)
So I want to find the most occurring one and so on till 10th most occurring number.
use array_count_values, here is your reference link http://www.w3schools.com/php/func_array_count_values.asp
<?php
$a=array("A","Cat","Dog","A","Dog");
print_r(array_count_values($a));
?>
Output
Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
So i have 3 different ( yet they share some similarities ) and i would like to combine these into one to perform some calculations
Array
(
[0] => Array
(
[0] => Agent
[1] => Answered
[2] => Missed
[3] => Contribution
[4] => Per Hour
[5] => Total Ring Time
[6] => Mean Ring Time
[7] => Total Talk Time
[8] => Mean Talk Time
[9] => Total Wrap Time
[10] => Mean Wrap Time
[11] => Total Session Time
[12] => Mean Session Time
[13] => Number of Sessions
[14] => % Util
[15] => Agent Hang-Ups
[16] => Caller Hang-Ups
[17] => Agent Hang-Ups Percent
[18] => Caller Hang-Ups Percent
)
[1] => Array
(
[0] => Amber
[1] => 16
[3] => 2.0%
[4] => 0.2
[5] => 28.6
[6] => 1.8
[7] => 1861.1
[8] => 116.3
[9] => 0.0
[10] => 0.0
[11] => 234862.2
[12] => 3403.8
[13] => 69.0
[14] => 0.8%
[15] => 10
[16] => 6
[17] => 62.5%
[18] => 37.5%
)
[2] => Array
(
[0] => Amie
[1] => 106
[3] => 13.5%
[4] => 3.0
[5] => 721.7
[6] => 6.8
[7] => 12268.0
[8] => 115.7
[9] => 0.0
[10] => 0.0
[11] => 127011.0
[12] => 6350.5
[13] => 20.0
[14] => 9.7%
[15] => 54
[16] => 52
[17] => 50.9%
[18] => 49.1%
)
)
Array 2
Array
(
[0] => Array
(
[0] => Agent
[1] => Answered
[2] => Missed
[3] => Contribution
[4] => Per Hour
[5] => Total Ring Time
[6] => Mean Ring Time
[7] => Total Talk Time
[8] => Mean Talk Time
[9] => Total Wrap Time
[10] => Mean Wrap Time
[11] => Total Session Time
[12] => Mean Session Time
[13] => Number of Sessions
[14] => % Util
[15] => Agent Hang-Ups
[16] => Caller Hang-Ups
[17] => Agent Hang-Ups Percent
[18] => Caller Hang-Ups Percent
)
)
Array 3
[0] => Array
(
[0] => Agent
[1] => Answered
[2] => Missed
[3] => Contribution
[4] => Per Hour
[5] => Total Ring Time
[6] => Mean Ring Time
[7] => Total Talk Time
[8] => Mean Talk Time
[9] => Total Wrap Time
[10] => Mean Wrap Time
[11] => Total Session Time
[12] => Mean Session Time
[13] => Number of Sessions
[14] => % Util
[15] => Agent Hang-Ups
[16] => Caller Hang-Ups
[17] => Agent Hang-Ups Percent
[18] => Caller Hang-Ups Percent
)
[1] => Array
(
[0] => (7312
[1] => 1
[3] => 0.0%
[4] => 459.8
[5] => 0.0
[6] => 0.0
[7] => 0.4
[8] => 0.4
[9] => 0.0
[10] => 0.0
[11] => 7.8
[12] => 2.6
[13] => 3.0
[14] => 5.5%
[15] => 1
[17] => 100.0%
[18] => 0.0%
)
[2] => Array
(
[0] => Amber
[1] => 414
[2] => 9
[3] => 9.3%
[4] => 6.3
[5] => 1880.1
[6] => 4.4
[7] => 65209.8
[8] => 157.5
[9] => 240.4
[10] => 0.6
[11] => 234862.2
[12] => 3403.8
[13] => 69.0
[14] => 27.8%
[15] => 290
[16] => 124
[17] => 70.0%
[18] => 30.0%
)
So in this example i have 3 arrays, all have the same first initial array. But these arrays can differ in size and they may not share the same people in in.
People can also be in different places so i.e.
Array 1 : Common -> Amber -> Amie
Array 2 : Common ->
Array 3 : Common -> 7312 -> Amber ->Amie
Now the final array should look like
Array 4 : Common -> 7312 -> Amber -> Amie
All the values from all arrays should also be combined so i.e:
Amber 1st array / 1st value : 16
Amber 2nd array / 2nd value : 414
Amber final array value : 414 + 16 = 430
Hopefully i have made question clear.
Basically, you sum up all the info you got, remove the headers. Then rebuild a new array with the info consolidation.
//merge all arrays, remove the first element, it is headers.
$my_total_array = array_merge(
array_splice($array1,1),
array_splice($array2,1),
array_splice($array3,1)
);
$myagents = array();
foreach($my_total_array as $agent){
if(!isset($myagents[$agent[0]])){
//Never met the agent, add them.
$myagents[$agent[0]] = $agent;
}else{
//We already seen the agent, do maths.
$myagents[$agent[0]][1]+=$agent[1];
//TODO: Apply consolidation rules for other fields.
}
}
//Put the headings back at the beggining.
array_unshift($myagents,$array1[0]);
print_r($myagents);
I hope this helps.
EDIT: From PHP Docs
Merges the elements of one or more arrays together so that the values
of one are appended to the end of the previous one. It returns the
resulting array.
If the input arrays have the same string keys, then the later value
for that key will overwrite the previous one. If, however, the arrays
contain numeric keys, the later value will not overwrite the original
value, but will be appended.
I have a array called $array which is multidimensional array. It consits of keys like brandname, productsubcategory (Keys are not static they can be anything and even number of keys are not fixed). I want all the common values from the array
Current array:
$array = array
(
[brandname] => Array
(
[0] => Array
(
[0] => sony_brandname
[1] => touch screen_type
[3] => 2.8_size
[4] => gsm + gsm_sim_support
[5] => 2_primary_camera
[6] => 64 mb_internal_memory
[7] => 32_expandable_memory
[8] => 1200_standard_battery_type
[9] => 3_size
[10] => 1000_standard_battery_type
[11] => touch and type_type
)
)
[productsubcategory] => Array
(
[1] => Array
(
[0] => karbonn_brandname
[1] => touch and type_type
[2] => micromax_brandname
[3] => 2.8_size
[4] => gsm_sim_support
[5] => 3.15_primary_camera
[6] => 52 mb_internal_memory
[7] => 8_expandable_memory
[8] => 1000_standard_battery_type
[9] => nokia_brandname
[10] => symbian s40_os_clean
[11] => 5_primary_camera
[12] => 128 mb_ram
[13] => 256 mb_internal_memory
[14] => 32_expandable_memory
[15] => 1110_standard_battery_type
[16] => gsm + gsm_sim_support
[17] => 2_primary_camera
[18] => 32 mb_ram
[19] => 10 mb_internal_memory
[20] => no_expandable_memory
[21] => 1020_standard_battery_type
[22] => 680 mhz_processor
[23] => 64 mb_ram
[24] => 128 mb_internal_memory
[25] => 860_standard_battery_type
[26] => blackberry_brandname
[27] => 2.45_size
[28] => 1 ghz_processor
)
)
);
Desired array :
$array = array
(
[0] => sony_brandname
[1] => touch and type_type
[2] => 2.8_size
[8] => 1000_standard_battery_type
[16] => gsm + gsm_sim_support
[17] => 2_primary_camera
)
Use array_intersect():
$result = array_intersect($array["brandname"][0], $array["productsubcategory"][1]);
print_r($result);