Now, I'm try to change date format from year-month-day to month/day/year form array.
I have an array that contains multiple dates in array i want to change each date format to year-month-day to month/day/year. Please check below array that contains multiple dates. Please help me if know something about that.
Array
(
[0] => 2018-05-19
[1] => 2018-05-20
[2] => 2018-05-21
[3] => 2018-05-22
[4] => 2018-05-23
[5] => 2018-05-24
[6] => 2018-05-25
[7] => 2018-05-26
[8] => 2018-05-27
[9] => 2018-05-28
[10] => 2018-05-29
[11] => 2018-05-30
[12] => 2018-05-31
[13] => 2018-06-04
[14] => 2018-06-05
[15] => 2018-06-08
[16] => 2018-06-09
[17] => 2018-06-10
[18] => 2018-06-13
[19] => 2018-06-14
[20] => 2018-06-15
[21] => 2018-06-17
[22] => 2018-06-20
[23] => 2018-06-21
[24] => 2018-06-24
[25] => 2018-06-28
[26] => 2018-06-29
[27] => 2018-07-02
[28] => 2018-07-05
[29] => 2018-07-11
[30] => 2018-07-12
[31] => 2018-07-15
[32] => 2018-07-16
[33] => 2018-07-17
[34] => 2018-07-20
[35] => 2018-07-23
[36] => 2018-07-24
[37] => 2018-07-25
[38] => 2018-07-26
[39] => 2018-07-27
[40] => 2018-07-29
[41] => 2018-08-07
[42] => 2018-08-08
[43] => 2018-08-10
[44] => 2018-08-11
[45] => 2018-08-12
[46] => 2018-08-13
[47] => 2018-08-15
[48] => 2018-08-17
[49] => 2018-08-18
[50] => 2018-08-19
[51] => 2018-08-20
[52] => 2018-08-21
[53] => 2018-08-25
[54] => 2018-08-26
[55] => 2018-08-27
[56] => 2018-08-28
[57] => 2018-08-29
[58] => 2018-08-30
)
I have an array that contains multiple dates in array i want to change each date format to year-month-day to month/day/year. Please check below array that contains multiple dates. Please help me if know something about that.
Here you go:
<?php
$currentDates = [
'2018-05-19',
'2018-05-20',
'2018-05-21',
'2018-05-22',
'2018-05-23',
'2018-05-24',
'2018-05-25',
'2018-05-26',
'2018-05-27',
'2018-05-28',
'2018-05-29',
'2018-05-30',
'2018-05-31',
'2018-06-04',
'2018-06-05',
'2018-06-08',
'2018-06-09',
'2018-06-10',
'2018-06-13',
'2018-06-14',
'2018-06-15',
'2018-06-17',
'2018-06-20',
'2018-06-21',
'2018-06-24',
'2018-06-28',
'2018-06-29',
'2018-07-02',
'2018-07-05',
'2018-07-11',
'2018-07-12',
'2018-07-15',
'2018-07-16',
'2018-07-17',
'2018-07-20',
'2018-07-23',
'2018-07-24',
'2018-07-25',
'2018-07-26',
'2018-07-27',
'2018-07-29',
'2018-08-07',
'2018-08-08',
'2018-08-10',
'2018-08-11',
'2018-08-12',
'2018-08-13',
'2018-08-15',
'2018-08-17',
'2018-08-18',
'2018-08-19',
'2018-08-20',
'2018-08-21',
'2018-08-25',
'2018-08-26',
'2018-08-27',
'2018-08-28',
'2018-08-29',
'2018-08-30',
];
$changedDates = array_map(function ($date) {
return date('m/d/Y', strtotime($date));
}, $currentDates);
var_dump($changedDates);
<?php
$dates = Array
("2018-05-19", "2018-05-20", "2018-05-21", "2018-05-22","2018-05-23");
print_r($dates);
$newDateFormat = array();
foreach($dates as $date){
$date = date('m/d/Y', strtotime($date));
array_push($newDateFormat,$date);
}
print_r($newDateFormat);
?>
I Think it will help you.
<?php
function convert_YYYYMMDD_to_MMDDYYYY($str)
{
return substr($str, 5, 2) . '/' . substr($str, 8, 2) . '/' . substr($str, 0, 4);
}
for ($i =0 ; $i < count($arr) ; $i++)
{
$arr[$i] = convert_YYYYMMDD_to_MMDDYYYY($arr[$i]);
}
?>
I have the following array
Array ( [0] => **start** [1] => **start** [2] => name [3] => producer [4] => contact name [5] => 03354222271 [6] => fzahid001#gmail.com [7] => day contact name [8] => 03354222271 [9] => venue name [10] => adress [11] => country [12] => city [13] => desc [14] => file [15] => 2016-01-01 [16] => 01:00 [17] => 06:00 [18] => 2 [19] => music_festival [20] => 2000+ [21] => quick [22] => alcohol [23] => quick [24] => 10x10 [25] => ***no*** [26] => ***no*** [27] => ***no*** [28] => 2 [29] => 0 [30] => 4 [31] => $158 [32] => $118.5 [33] => $284 [34] => $960 [35] => **start** [36] => na [37] => producer [38] => con [39] => 1 [40] => fzahid001#gmail.com [41] => nam [42] => 1 [43] => venue [44] => ad [45] => co [46] => ci [47] => description test [48] => download555ssss.png [49] => 2016-12-07 [50] => 13:00 [51] => 19:00 [52] => 2 [53] => manual_selection [54] => ATV [55] => 10x10 [56] => no [57] => no [58] => no [59] => 1 [60] => 1 [61] => 1 [62] => $109.5 [63] => $118.5 [64] => $99.5 [65] => $728 [66] => **start** [67] => Race [68] => Race Club [69] => Faizan [70] => 03354222271 [71] => fzahid001#gmail.com [72] => Faizan Zahid [73] => 03354222271 [74] => DHA [75] => 90-H Tariq Gardens [76] => Pakistan [77] => Lahore [78] => [79] => images.jpg [80] => 2017-01-01 [81] => 00:00 [82] => 07:00 [83] => 2 [84] => cycling_road_race [85] => 1_field [86] => 1_399 [87] => electronic [88] => quick [89] => 10x10 [90] => no [91] => no [92] => no [93] => 1 [94] => 0 [95] => 1 [96] => $109.5 [97] => $118.5 [98] => $99.5 [99] => $796.5 [100] => )
Now what I want to do is, remove the consecutive duplicates of "start". I am currently using following code
foreach ($updateddata as $value){
if($value != $previousvalue){
array_push($finaldata, $value);
}
$previousvalue = $value;
}
but is also removes other consecutive duplicates as well which I don't want to remove. Kindly help me how to do this.
I have highlighted the occurrences of "start" which I want to remove and make it one single entry, while leaving the other string as it is e.g. I don't want to remove the duplicates of string "no"
Try this
if($value != $previousvalue){
array_push($finaldata, $value);
} else if( $value != 'start'){
array_push($finaldata, $value);
}
To remove the consecutive duplicates of "start" value you should restrict the crucial condition to that value. Use the following approach:
// exemplary array
$updateddata = [
'start', 'start', 'producer', 'contact', 'no', 'no'
];
foreach ($updateddata as $k => $v) {
if (isset($updateddata[$k-1]) && $v == 'start' && $v == $updateddata[$k-1]) {
unset($updateddata[$k]);
}
}
The output:
Array
(
[0] => start
[2] => producer
[3] => contact
[4] => no
[5] => no
)
I need to generate a grid ( +6.00 at -15.00 ) ! Somebody can help me ? PHP CODE please.
6.00
5.75
5.50
5.25
5.00
.
.
.
.
-15.00
"Actual Credit Goes To #Mark Baker"
But Here I just put it in a good shape and here is exactly how you can do it :
<?php
$grid = range(6, -15, 0.25);
echo "<pre>";
print_r($grid);
echo "</pre>";
?>
Here is Output of the Code :
Array
(
[0] => 6
[1] => 5.75
[2] => 5.5
[3] => 5.25
[4] => 5
[5] => 4.75
[6] => 4.5
[7] => 4.25
[8] => 4
[9] => 3.75
[10] => 3.5
[11] => 3.25
[12] => 3
[13] => 2.75
[14] => 2.5
[15] => 2.25
[16] => 2
[17] => 1.75
[18] => 1.5
[19] => 1.25
[20] => 1
[21] => 0.75
[22] => 0.5
[23] => 0.25
[24] => 0
[25] => -0.25
[26] => -0.5
[27] => -0.75
[28] => -1
[29] => -1.25
[30] => -1.5
[31] => -1.75
[32] => -2
[33] => -2.25
[34] => -2.5
[35] => -2.75
[36] => -3
[37] => -3.25
[38] => -3.5
[39] => -3.75
[40] => -4
[41] => -4.25
[42] => -4.5
[43] => -4.75
[44] => -5
[45] => -5.25
[46] => -5.5
[47] => -5.75
[48] => -6
[49] => -6.25
[50] => -6.5
[51] => -6.75
[52] => -7
[53] => -7.25
[54] => -7.5
[55] => -7.75
[56] => -8
[57] => -8.25
[58] => -8.5
[59] => -8.75
[60] => -9
[61] => -9.25
[62] => -9.5
[63] => -9.75
[64] => -10
[65] => -10.25
[66] => -10.5
[67] => -10.75
[68] => -11
[69] => -11.25
[70] => -11.5
[71] => -11.75
[72] => -12
[73] => -12.25
[74] => -12.5
[75] => -12.75
[76] => -13
[77] => -13.25
[78] => -13.5
[79] => -13.75
[80] => -14
[81] => -14.25
[82] => -14.5
[83] => -14.75
[84] => -15
)
I am attempting to make an array of IDs and use that array in another query to make sure the 2nd query results have the same ids that are in the array.
As per the requirements of the rest of my code, I would prefer not to use the join method.
$topartistsquery = "SELECT main_id FROM pages WHERE catnum = '201' AND top100 = 'y'";
$result = mysql_query($topartistsquery);
$topartistarray = array();
while(($row = mysql_fetch_assoc($result))) {
$topartistarray[] = $row['main_id'];
}
//print_r($topartistarray);
$eventquery = mysql_query("SELECT * FROM TNDB_CSV2 WHERE City = '".$city."' AND PCatID = '2' AND PerformerID IN ($topartistarray) AND DateTime >= CURDATE() ORDER BY DateTime LIMIT 3");
Here is the output of the $topartistarray:
Array ( [0] => 28 [1] => 1126 [2] => 47643 [3] => 2769 [4] => 41512 [5] => 1429 [6] => 163 [7] => 48418 [8] => 198 [9] => 3748 [10] => 10161 [11] => 39890 [12] => 14160 [13] => 25407 [14] => 29219 [15] => 36980 [16] => 1860 [17] => 41299 [18] => 342 [19] => 7468 [20] => 33205 [21] => 1564 [22] => 33911 [23] => 15183 [24] => 540 [25] => 974 [26] => 8358 [27] => 30678 [28] => 4804 [29] => 4266 [30] => 517 [31] => 522 [32] => 1550 [33] => 15989 [34] => 930 [35] => 3383 [36] => 26468 [37] => 5560 [38] => 1063 [39] => 2870 [40] => 4055 [41] => 24917 [42] => 46223 [43] => 973 [44] => 334 [45] => 27970 [46] => 27985 [47] => 356 [48] => 6655 [49] => 201 [50] => 1930 [51] => 1069 [52] => 38053 [53] => 397 [54] => 21713 [55] => 53725 [56] => 4941 [57] => 864 [58] => 41904 [59] => 59233 [60] => 53970 [61] => 50875 [62] => 54175 [63] => 56861 [64] => 53317 [65] => 55258 [66] => 823 [67] => 55704 [68] => 59797 [69] => 27866 [70] => 123 [71] => 59749 [72] => 1567 [73] => 34851 [74] => 3399 [75] => 58674 [76] => 59442 [77] => 60334 )
Any constructive input is greatly appreciated. Thank you in advance
Try this:
if (isset($topartistarray) and count($topartistarray) {
$eventquery = mysql_query("SELECT * FROM TNDB_CSV2 WHERE City = '".$city."' AND PCatID = '2' AND PerformerID IN (".implode(",",$topartistarray).") AND DateTime >= CURDATE() ORDER BY DateTime LIMIT 3");
} else {
$eventquery = false;
}
I have two arrays:
$array1:
Array
(
[0] => 2032
[1] => 2027
[2] => 2025
[3] => 2023
[4] => 2021
[5] => 2018
[6] => 2014
[7] => 2011
[8] => 2009
[9] => 1947
[10] => 1941
[11] => 1939
[12] => 1937
[13] => 1935
[14] => 1933
[15] => 1928
[16] => 1926
[17] => 1924
[18] => 1922
[19] => 1920
[20] => 1918
[21] => 1916
[22] => 1910
[23] => 1881
[24] => 1680
[25] => 1678
[26] => 1879
[27] => 1877
[28] => 1875
[29] => 1873
[30] => 1871
[31] => 1869
[32] => 1865
[33] => 1863
[34] => 1858
[35] => 1850
[36] => 1844
[37] => 1838
[38] => 1829
[39] => 1827
[40] => 1825
[41] => 1821
[42] => 1819
[43] => 1814
[44] => 1812
[45] => 1810
[46] => 1808
[47] => 1806
[48] => 1804
[49] => 1801
[50] => 1793
[51] => 1791
[52] => 1789
[53] => 1784
[54] => 1774
[55] => 1772
[56] => 1770
[57] => 1768
[58] => 1766
[59] => 1764
[60] => 1762
[61] => 1760
[62] => 1754
[63] => 1748
[64] => 1746
[65] => 1744
[66] => 1740
[67] => 1738
[68] => 1732
[69] => 1722
[70] => 1720
[71] => 1716
[72] => 1714
[73] => 1711
[74] => 1708
[75] => 1703
[76] => 1699
[77] => 1673
[78] => 1671
[79] => 1669
[80] => 1667
[81] => 1665
[82] => 1663
[83] => 1661
[84] => 1659
[85] => 1655
)
$array2:
Array
(
[0] => 1665
[1] => 1671
[2] => 1714
[3] => 1716
[4] => 1722
[5] => 1732
[6] => 1774
[7] => 1801
[8] => 1804
[9] => 1916
[10] => 1918
[11] => 1920
[12] => 1924
[13] => 1933
[14] => 1935
[15] => 1939
)
What I need to do is check each value of array one and see if it is in array two, if the value is in array two then place that value into array three. But array three needs to stay in the order that the values appear in array one.
I can just write some code to loop through array one do an in_array() and if true drop into array three. This would work but the reason for my question is that is there any function already available for this task? If not then whats the most effiecient and speedy way to do this?
$array3 = array_intersect($array, $array2)
http://php.net/manual/en/function.array-intersect.php
you can use array_intersect().
http://php.net/manual/en/function.array-intersect.php