I have an array named $info. I want to replace string "YES" found wherever within the array with space or empty string.How can it be done?
Below is the code:
<?php
$conn = mysql_connect("localhost" , "root" , "") or die("Can not connect." . mysql_error());
$db = mysql_select_db("leothian" , $conn) or die("Can not connect." . mysql_error());
$selTable = "select * from dump_hotelbasicinfo ORDER BY id ASC LIMIT 5";
$resultTable = mysql_query($selTable,$conn);
while($rowTable = mysql_fetch_array($resultTable))
{
$selQuery = "SELECT * FROM dump_hotelamenities WHERE HotelCode='$rowTable[HotelCode]' LIMIT 5";
$resultQuery = mysql_query($selQuery);
while($row=mysql_fetch_array($resultQuery))
{
echo "<br> Hotel Code : " .$row['HotelCode'];
$info = array();
$info = (explode(';',$row['PAmenities']));
echo array_search("YES",$info);
echo "<br> Hotel Features : " ;
print_r( $info);
echo "<hr>";
}
}
?>
OUTPUT :
Hotel Features : Array ( [0] => Small pets allowed under 5 kg [1] => YES Small pets allowed under 5 kg [2] => Large pets allowed over 5 kg [3] => YES Large pets allowed over 5 kg [4] => Wheelchair-accessible [5] => YES Wheelchair-accessible [6] => Car park [7] => YES Car park [8] => Garage [9] => YES Garage [10] => Mobile phone coverage [11] => Wired Internet [12] => Wi-fi [13] => Transfer service [14] => Secure parking [15] => Room service [16] => Laundry service [17] => Hotel safe [18] => Cloakroom [19] => Lift access [20] => Newspaper stand [21] => Supermarket [22] => Bicycle storage [23] => Sun terrace [24] => Gym [25] => Newspapers [26] => Restaurant [27] => Non-smoking area [28] => Photocopier [29] => Sun loungers [30] => Children& [31] => apos [32] => s play area [33] => TV lounge [34] => Sauna [35] => Massage [36] => Spa treatments [37] => Year of construction - 2008 [38] => Number of floors main building - 10 [39] => Apartments - 25 [40] => Studios - 1 [41] => Connecting rooms [42] => YES Connecting rooms [43] => Apartment complex [44] => Nearest Bus / Metro Stop - 25000 m [45] => Ski slopes - 2000 m )
A for each loop would work
foreach($info as $k=>$v)
$info[$k] = str_replace('YES','',$v);
<?php
$array = array('this','is','a','test','yes it is','YES it is');
$array = array_map(function($item){
$item = str_replace('YES','', $item);
return $item;
}, $array);
var_dump($array);
function customSearch($keyword, $arrayToSearch){
foreach($arrayToSearch as $key => $arrayItem){
if( stristr( $arrayItem, $keyword ) ){
$arrayToSearch[key] = "yes";
return $key;
}
}
}
I haven't actually tried this but please Refer to this question here if my code is a bit off:
Search for PHP array element containing string
Related
i am writing a script to reach out to a website that downloads a csv into cache and then parses the data into an array.
$base_url = "http://www.collincad.org/ccad/propertysearch/download.php?situs_num=1707&situs_street=university&situs_street_suffix=&isd%5B%5D=any&city%5B%5D=any&prop_type%5B%5D=R&prop_type%5B%5D=P&prop_type%5B%5D=MH&active%5B%5D=1&year=2018";
$handle = fopen($base_url, "r");
$flag = true;
while(!feof($handle))
{
$text = fgetcsv($handle, 1024, ",");
if($flag) { $flag = false; continue; }
print $text[1]. " <br>";
}
mysql_close($connect);
When performing the query this way it has the first row and a row of other data and ignores the comma.
$base_url = "export5.csv";
$handle = fopen($base_url, "r");
$flag = true;
while(!feof($handle))
{
$text = fgetcsv($handle, 1024, ",");
if($flag) { $flag = false; continue; }
print $text[1]. " <br>";
}
mysql_close($connect);
but when i manually download the csv file it and read it from the local folder it works as expected... i would prefer not to make this a two step process... im thinking that reading direct from the site with php is the issue, just can figure out how to resolve it.
Thanks
First and foremost when using fopen with a web url, make sure your server is configured to allow it (http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen). Once that is out of the way you should be fine with your code.
The issue though is the CSV format itself.
Looking at the CSV return of that url, its delimiters are tabs, not commas. And I see no enclosures too. So you need to change your fgetcsv to:
$text = fgetcsv($handle, 1024, "\t", '');
And it should begin to return results like this (for each $text):
Array
(
[0] => 15071
[1] => 2018
[2] => P
[3] => Personal
[4] => P-9000-288-0243-1
[5] => N
[6] => ZZZZZZZ BPP # 1707 W UNIVERSITY DR
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] => BPP AT 1707 W UNIVERSITY DR
[13] => KROGER #488
[14] => 1707
[15] => UNIVERSITY DR
[16] => MCKINNEY
[17] => 1707 W University Dr | McKinney, TX 75069
[18] => 844925
[19] => THE KROGER CO
[20] => CMC
[21] => MCKINNEY CITY
[22] => SMC
[23] => MCKINNEY ISD
[24] =>
[25] => Active
[26] => No
[27] =>
)
Also, the first line in the csv file is this:
Line 1:
Array
(
[0] => sep=
[1] =>
)
So you may want to skip the first TWO lines (the second line being the column headers).
Line 2: (column headers)
Array
(
[0] => Property ID
[1] => Year
[2] => Property Type Code
[3] => Property Type Description
[4] => Geographic ID
[5] => Abstract Or Subdivision Code
[6] => Abstract Or Subdivision Description
[7] => Block
[8] => Tract Or Lot
[9] => Mobile Home Park Code
[10] => Mobile Home Park Description
[11] => Mobile Home Park Space
[12] => Legal Description
[13] => Doing Business As
[14] => Street Number
[15] => Street Name
[16] => City
[17] => Complete Address
[18] => Owner ID
[19] => Owner Name
[20] => Taxing City Code
[21] => Taxing City Name
[22] => Taxing School District Code
[23] => Taxing School District Name
[24] => Market Value
[25] => Property Status
[26] => Certified Data
[27] =>
)
This code was written 10-15 years ago from what I can see. Friday, the webhost stopped supporting php4 and forced upgrade to 5.6.23 and the web app stopped working. I have been going over it all weekend. Got the system running, but there is one serious issue and I've narrowed it to a specific line of code and still can't figure it out due to my not doing php OOP programming myself. Looking for a quick fix here as my friend is dead in the water.
This code:
$ins = & $_SESSION["ins"];
$serv = new Services();
print "post - ";
print_r($_POST)."<br />";
reset($_POST);
foreach ($_POST as $key => $value) {
//$key = addslashes($key);
$query = mysql_query("SELECT $valueNumber
FROM CLIENTS_SERVICES
where serviceID = '$key' and clientID = '$ins->client' and effectiveDate <= '$effectiveDate'
order by effectiveDate DESC LIMIT 1")
or die("SELECT services function query failed!!");
$query_data = mysql_fetch_object($query);
$serv->value = $query_data->$valueNumber;
$serv->quantity = $value;
$ins->services[$key] = $serv; //<----- this is the offender
// Calculate services running total
$total = $total + ($serv->quantity * $serv->value);
print $key." - key<br />";
print $value." - value<br />";
print "serv array - ";
print_r($serv);
print "<br />";
print "ins array - ";
print_r($ins->services);
print "<br />";
print $total." - total<br />";
}
outputs:
post - Array (
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] => 1.5
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] => 3
[17] =>
[50] =>
[51] => 1.75
[58] =>
[save_services] => Save )
6 - key
1.5 - value
serv object - Services Object ( [quantity] => 1.5 [value] => 56 )
ins array - Array ( [6] => Services Object ( [quantity] => 1.5 [value] => 56 ) )
84 - total
16 - key
3 - value
serv object - Services Object ( [quantity] => 3 [value] => 45 )
ins array - Array ( [6] => Services Object ( [quantity] => 3 [value] => 45 ) [16] => Services Object ( [quantity] => 3 [value] => 45 ) )
219 - total
51 - key
1.75 - value
serv object - Services Object ( [quantity] => 1.75 [value] => 118 )
ins array - Array ( [6] => Services Object ( [quantity] => 1.75 [value] => 118 ) [16] => Services Object ( [quantity] => 1.75 [value] => 118 ) [51] => Services Object ( [quantity] => 1.75 [value] => 118 ) )
425.5 - total
In a nutshell, I cannot understand why the most recent object values are overwriting the previous array entries. I've spent the weekend trying to figure out what changed between the old version (4.?) and the new 5.6.23, and have been on dozens of dead ends and wild goose chases. Ignorance is not bliss.
If there is a pointer to the resolution, or you can offer some insight, I'd appreciate it.
Create a new instance of services inside of the loop
foreach ($_POST as $key => $value) {
$serv = new Services();
...
}
When you use objects in php it will use the same pointer to that object
I want to split array into two on the basis of value.
For example
Array(
[25] => Korea Strawberry (Pkt) 250g
[26] => *8887187338308
[27] => PROM Mix 2#38.9G
[28] => 19.90*2 38.90 Z
[29] => 0.45*2
[30] =>
[31] =>
[32] => Total with GST # 6%
[33] => Rounding
[34] => Total
[35] => Tender
[36] => Master 0003 App: 807946
[37] => Change
[38] => GST Analysis Goods Tax Amount
[39] => S = 6%
[40] => Item 3
[41] => Qty 4
[42] => Total Saving 9.44
[43] => 56.94
)
I want it to be in two parts. One all the values before Total with GST # 6% second all remaining values.
How can I do that. I tried array_diff() and other methods but didn't work as what I want.
You could get the key number for Total with GST # 6% using array_search then split the array using 2 loops.
$array = Array(
[25] => Korea Strawberry (Pkt) 250g
[26] => *8887187338308
[27] => PROM Mix 2#38.9G
[28] => 19.90*2 38.90 Z
[29] => 0.45*2
[30] =>
[31] =>
[32] => Total with GST # 6%
[33] => Rounding
[34] => Total
[35] => Tender
[36] => Master 0003 App: 807946
[37] => Change
[38] => GST Analysis Goods Tax Amount
[39] => S = 6%
[40] => Item 3
[41] => Qty 4
[42] => Total Saving 9.44
[43] => 56.94
);
$value = 'Total with GST # 6%'; //This can be dynamically filled
$split = array_search($value, $array)
for($i=0; $i<$split; $i++) {
$newArray1[] = $array[$i];
}
for($i=$split; $i<count($array); $i++) {
$newArray2[] = $array[$i];
}
unset($array); //Now it's split we can unset the $array variable
You are looking for array_slice.
Just be careful about using it on associative arrays, or arrays with arbitrary numerical keys.
I have use joins to retrieve the data from various tables and I am successful in it but when I want to retrieve it the query only show me the result of last row even though I have use while loop on it but its not working properly give me the one result only which belongs to last row .
Here is my php scrip.
include("connections/conn.php");
$sql = mysql_query("SELECT * FROM `tbl_cart` as c join " .
"`tbl_product` as p join " .
"`tbl_catagory` as ca join " .
"`tbl_compony` as co join " .
"`tbl_images` as i " .
"on c.pid=p.pro_id " .
"and p.compony=co.com_id " .
"and p.catagory=ca.cat_id " .
"and p.pro_id=i.p_id");
$row = mysql_fetch_array($sql);
while($row1 = mysql_fetch_array($sql)) {
$product_ids[]=$row1['pro_id'];
foreach($product_ids as $pro) {
echo $pro;
}
}
but the array contains this data. which have more result of from similar columns.
111Array ( [0] => 33 [cart_id] => 33 [1] => 110 [pid] => 110 [2] => 20 [quantity] => 20 [3] => 65,000 [price] => 65,000 [4] => 9 [userid] => 9 [5] => 2014-08-14 [dated] => 2013-08-24 [6] => 110 [pro_id] => 110 [7] => Aspire S3-391 [title] => Aspire S3-391 [8] => 10.68 lbs [weight] => 10.68 lbs [9] => 15.90 inch [width] => 15.90 inch [10] => 2.31 cm [height] => 2.31 cm [11] => Black [color] => Black [12] => 65,000 [13] => $1499 [USD] => $1499 [14] => [waranty] => [15] => Make work a touch easier.Get in touch with your productive side. Tap and scroll your way through the workday with an intuitive touch screen (select models) that helps you work so much smarter. Count on durability inside and out from built in security to the spill resistant keyboard and a thin light design thats packed with style. [description] => Make work a touch easier.Get in touch with your productive side. Tap and scroll your way through the workday with an intuitive touch screen (select models) that helps you work so much smarter. Count on durability inside and out from built in security to the spill resistant keyboard and a thin light design thats packed with style. [16] => 1 [catagory] => 1 [17] => 4 [compony] => 4 [18] => Intel® Core™ i5 [l_ptype] => Intel® Core™ i5 [19] => 2.8 GHZ [l_pspeed] => 2.8 GHZ [20] => 700 GB [l_harddisk] => 700 GB [21] => 4GB DDR3 [l_RAM] => 4GB DDR3 [22] => Windows 8 [l_op] => Windows 8 [23] => [l_battery] => [24] => [lcd_brightness] => [25] => [lcd_contrast] => [26] => [lcd_imagesize] => [27] => [lcd_pixelsize] => [28] => [lcd_resolution] => [29] => [lcd_backlight] => [30] => [lcd_depth] => [31] => [p_pspeed] => [32] => [p_resolution] => [33] => [p_pconsumption] => [34] => [p_memorycapacity] => [35] => [p_storagecapacity] => [36] => [p_interface] => [37] => [p_processorspeed] => [38] => [pro_p_consumption] => [39] => [pro_brightness] => [40] => [pro_resolution] => [41] => [pro_imagesize] => [42] => [pro_ptype] => [43] => [pro_imagesignal] => [44] => [pro_contrast] => [45] => [sca_capacity] => [46] => [sca_speed] => [47] => [sca_colordepth] => [48] => [sca_usb] => [49] => [sca_documentsize] => [50] => [sca_resolution] => [51] => 2013-08-24 [52] => 1 [cat_id] => 1 [53] => Laptop [cat_title] => Laptop [54] => 4 [com_id] => 4 [55] => Acer [com_title] => Acer [56] => 120 [img_id] => 120 [57] => Aspire S3-391_main.jpg [main_image] => Aspire S3-391_main.jpg [58] => Aspire S3-391_left.jpg [left_image] => Aspire S3-391_left.jpg [59] => Aspire S3-391_right.jpg [right_image] => Aspire S3-391_right.jpg [60] => Aspire S3-391_top.jpg [top_image] => Aspire S3-391_top.jpg [61] => Aspire S3-391_other.jpg [other_image] => Aspire S3-391_other.jpg [62] => 110 [p_id] => 110 )
And when I run this query in sql it returns me two rows so how can I retrieve the data accordingly in my php script I am really confuse in it please help me out .
Now for further understanding i am adding this picture. And you people can see that this query is returning me two rows so how will fetch the two rows separately in my php script and show them on my page.
The problem is you are fetching the results from the same variable which bring you to a logical error see what's happening here you fetch once the result and store it in $row so first row from the result set get fetched and again your fetching the record and storing in another variable but from the same variable $sql and applying the while loop in result you are getting only one row because the first row get skipped.
Solution: Do not fetch the Results from the same variable make another variable and store the same query in it if you really needed e.g
$sql = mysql_query("SELECT * FROM `tbl_cart` as c join " .
"`tbl_product` as p join " .
"`tbl_catagory` as ca join " .
"`tbl_compony` as co join " .
"`tbl_images` as i " .
"on c.pid=p.pro_id " .
"and p.compony=co.com_id " .
"and p.catagory=ca.cat_id " .
"and p.pro_id=i.p_id");
$sql1 = mysql_query("SELECT * FROM `tbl_cart` as c join " .
"`tbl_product` as p join " .
"`tbl_catagory` as ca join " .
"`tbl_compony` as co join " .
"`tbl_images` as i " .
"on c.pid=p.pro_id " .
"and p.compony=co.com_id " .
"and p.catagory=ca.cat_id " .
"and p.pro_id=i.p_id");
$row = mysql_fetch_array($sql);
while($row1= mysql_fetch_array($sql1))
{
echo $row1['pro_id'];
}
I hope this will work.
You have this statement:
$row = mysql_fetch_array($sql);
That will fetch the "first" from the resultset (if there's at least one row).
Then you have a while loop, that does another fetch:
$row1 = mysql_fetch_array($sql)
That will get the "second" and following row. (Since you've already retrieved the first row.)
If you don't want to "skip" that first row, then remove this line from your code:
$row = mysql_fetch_array($sql);
Seems to be logicial to get only last row result.
If inside the While loop, you put "echo 'in the loop';", you'll probably see that two times.
But as you do:
'$product_ids[]=$row1['pro_id'];'
you fill $product_ids[] first time with $row1['pro_id'] and, at next loop, you fill it again with the new value, destroying the first one.
In fact, you're making a common mistake and I suppose I understand what you want to do:
loop to getresult
display result
using
foreach($product_ids as $pro) {
echo $pro;
But you have put the foreach inside the while loop as it must be outside.
A most simple and understable way would be:
`$index=0;
while($row1 = mysql_fetch_array($sql))
{
$product_ids[$index]=$row1['pro_id'];
$index++;
}
foreach($product_ids as $pro) {
echo $pro;
}
}`
A detail: use another MySQL Driver, like mysqli as mysql basic driver is obsolote.
I have three arrays. One that contains the given title information from the user stored in $attributenames. The second has the data from the user stored in $anesdata. (So the first two are related) And the third is a dictionary so that I can get out the information I want using the index which is stored in $medicalInstanceDictionary.
This is the first one:
Array
(
[0] => PATIENT MRN
[1] => PATIENT LAST NAME
[2] => PATIENT FIRST NAME
[3] => PATIENT MIDDLE NAME
[4] => PATIENT SSN
[5] => PATIENT SEX
[6] => INVOICE
[7] => TRANSACTION
[8] => DATE OF PROCEDURE
[9] => POSTING DATE
[10] => LOCATION
[11] => CHARGE AMT
[12] => PROVIDER
[13] => FSC1
[14] => FSC2
[15] => PATIENT DOB
[16] => ATTENDING SURGEON
[17] => ATTENDING SURGEON
[18] => CPT CODES
[19] => ASA CLASSFICATION
[20] => ANESTHESIA CRNA
[21] => ANESTHESIA RESIDENT
[22] => SURGERY START TIME
[23] => SURGERY END TIME
[24] => SVC UNIT
[25] => FACILITY NAME
[26] => BILLING NUMBER
[27] => BILLING AREA NAME
[28] => PROCEDURE MODIFIER1
[29] => PROCEDURE MODIFIER2
[30] => PROCEDURE MODIFIER3
[31] => PRIMARY DX
[32] => SECONDARY DX
)
The second array is a two dimensional array, but each line is equivalent to one patient. So that first patient looks like this(put in x's instead of actual patient data):
[0] => Array
(
[0] => xxxx
[1] => xxxx
[2] => xxxx
[3] => xxxx
[4] => xxxxx
[5] => xxxx
[6] => xxxx
[7] => xxx
[8] => xxxxx
[9] => xxxx
[10] => xxxx
[11] => xxxxx
[12] => xxxx
[13] => xxxxx
[14] => xxxx
[15] => xxxx
[16] => xxxxxxx
[17] => xxxxx
[18] => xxxxx
[19] => xxxx
[20] =>
[21] => xxxxx
[22] => xxxxx
[23] => xxxxx
[24] => xxxxx
[25] => xxxx
[26] => xxxxx
[27] => xxxx
[28] => xxxxxxxx
[29] => xxxx
[30] =>
[31] => xxxxxxx
[32] => xxxxxxx
)
Then the dictionary looks like this:
$medicalInstanceDictionary = array(
'CPT CODES' => "CPT_Code",
'ASA CLASSFICATION' => "MG_ASA_Class",
'FACILITY NAME' => "Facility_Name",
'BILLING NUMBER' => "Billing_Number",
'BILLING AREA NAME' => "Billing_Area_Name",
'PROCEDURE MODIFIER1' => "Procedure_Modifier1",
'PROCEDURE MODIFIER2' => "Procedure_Modifier2",
'PRIMARY DX' => "Primary_Dx",
'SECONDARY DX' => "Secondary_Dx",
'INVOICE' => "FIN"
);
I am doing a nested foreach loop to get each row.
foreach ($dataarray as $dataindex => $datavalue)
{
$out = "";
foreach ($dictionary as $index => $value)
{
//find PATIENT MRN in $attributearray and get it's index
$attributeindex = array_search($index, $attributearray);
if ($attributeindex===FALSE) {
echo "Error : ".$index." not found <br />";
} else {
echo "<br>The attribute is: ".$value." The index is: ".$attributeindex."<br>";
}
(more code....)
}
(more code....)
}
That echo statement looks like this:
The attribute is: CPT_Code The index is: 18
The attribute is: MG_ASA_Class The index is: 19
The attribute is: Facility_Name The index is: 25
The attribute is: Billing_Number The index is: 26
The attribute is: Billing_Area_Name The index is: 27
The attribute is: Procedure_Modifier1 The index is: 28
The attribute is: Procedure_Modifier2 The index is: 29
The attribute is: Primary_Dx The index is: 31
Error : SECONDARY DX not found
The attribute is: FIN The index is: 6
I have no idea why it is skipping over Secondary_Dx. I have checked for spelling errors. I don't think it is my method of doing it because it only does not work for Secondary_Dx. The only thing I can think of is that it does something funky since it is the last element of the array. Has anyone seen this before?
Edit:
Added element(tried both methods, and both resulted in the same looking array using print_r:
//array_push($attributenames, "THE END");
$attributenames[] ="THE END";
echo "<pre>";
print_r($attributenames);
echo "</pre>";
output from that along with the error handling statement from above:
Array
(
[0] => PATIENT MRN
[1] => PATIENT LAST NAME
[2] => PATIENT FIRST NAME
[3] => PATIENT MIDDLE NAME
[4] => PATIENT SSN
[5] => PATIENT SEX
[6] => INVOICE
[7] => TRANSACTION
[8] => DATE OF PROCEDURE
[9] => POSTING DATE
[10] => LOCATION
[11] => CHARGE AMT
[12] => PROVIDER
[13] => FSC1
[14] => FSC2
[15] => PATIENT DOB
[16] => ATTENDING SURGEON
[17] => ATTENDING SURGEON
[18] => CPT CODES
[19] => ASA CLASSFICATION
[20] => ANESTHESIA CRNA
[21] => ANESTHESIA RESIDENT
[22] => SURGERY START TIME
[23] => SURGERY END TIME
[24] => SVC UNIT
[25] => FACILITY NAME
[26] => BILLING NUMBER
[27] => BILLING AREA NAME
[28] => PROCEDURE MODIFIER1
[29] => PROCEDURE MODIFIER2
[30] => PROCEDURE MODIFIER3
[31] => PRIMARY DX
[32] => SECONDARY DX
[33] => THE END
)
This is dictionary array Array
(
[CPT CODES] => CPT_Code
[ASA CLASSFICATION] => MG_ASA_Class
[FACILITY NAME] => Facility_Name
[BILLING NUMBER] => Billing_Number
[BILLING AREA NAME] => Billing_Area_Name
[PROCEDURE MODIFIER1] => Procedure_Modifier1
[PROCEDURE MODIFIER2] => Procedure_Modifier2
[PRIMARY DX] => Primary_Dx
[SECONDARY DX] => Secondary_Dx
[INVOICE] => FIN
)
The attribute is: CPT_Code The index is: 18
The attribute is: MG_ASA_Class The index is: 19
The attribute is: Facility_Name The index is: 25
The attribute is: Billing_Number The index is: 26
The attribute is: Billing_Area_Name The index is: 27
The attribute is: Procedure_Modifier1 The index is: 28
The attribute is: Procedure_Modifier2 The index is: 29
The attribute is: Primary_Dx The index is: 31
Error : SECONDARY DX not found
Array ( [0] => PATIENT MRN [1] => PATIENT LAST NAME [2] => PATIENT FIRST NAME [3] => PATIENT MIDDLE NAME [4] => PATIENT SSN [5] => PATIENT SEX [6] => INVOICE [7] => TRANSACTION [8] => DATE OF PROCEDURE [9] => POSTING DATE [10] => LOCATION [11] => CHARGE AMT [12] => PROVIDER [13] => FSC1 [14] => FSC2 [15] => PATIENT DOB [16] => ATTENDING SURGEON [17] => ATTENDING SURGEON [18] => CPT CODES [19] => ASA CLASSFICATION [20] => ANESTHESIA CRNA [21] => ANESTHESIA RESIDENT [22] => SURGERY START TIME [23] => SURGERY END TIME [24] => SVC UNIT [25] => FACILITY NAME [26] => BILLING NUMBER [27] => BILLING AREA NAME [28] => PROCEDURE MODIFIER1 [29] => PROCEDURE MODIFIER2 [30] => PROCEDURE MODIFIER3 [31] => PRIMARY DX [32] => SECONDARY DX [33] => THE END )
Array ( [CPT CODES] => CPT_Code [ASA CLASSFICATION] => MG_ASA_Class [FACILITY NAME] => Facility_Name [BILLING NUMBER] => Billing_Number [BILLING AREA NAME] => Billing_Area_Name [PROCEDURE MODIFIER1] => Procedure_Modifier1 [PROCEDURE MODIFIER2] => Procedure_Modifier2 [PRIMARY DX] => Primary_Dx [SECONDARY DX] => Secondary_Dx [INVOICE] => FIN )
The attribute is: FIN The index is: 6
You should test for a valid $attributeindex !
$attributeindex = array_search($index, $attributearray);
if ($attributeindex===FALSE) {
echo "Error : ".$index." not found <br />";
} else {
echo "<br>The attribute is: ".$value." The index is: ".$attributeindex."<br>";
}
If you get a not found Error you can be shure $index is not found in $attributearray .
Update :
This is very strange !
From your output we can clearly see.
$index == SECONDARY DX
and
$attributearray has a key [32]
[32] => SECONDARY DX
Only to test :
can you add to $attributearray at the end
[33] => 'END'
and see what happens.
Update 2 :
As i can see in the new output you got with
echo "<pre>";
print_r($attributenames);
echo "</pre>";
There is a empty line between [32] and [33].
There must be a invisible sign at the end of [32] => SECONDARY DX
I suspect a new line character.
Array
(
[0] => PATIENT MRN
[1] => PATIENT LAST NAME
....
[30] => PROCEDURE MODIFIER3
[31] => PRIMARY DX
[32] => SECONDARY DX
[33] => THE END
)
Try to remove that character and it should work .
TIP:
If you ever re experiencing similar behavior, you should check with :
for example:
echo bin2hex($attributenames[32]);
Output in windows look at the end :
5345434f4e444152592044580d0a
Where 0d is CR = Carriage return and 0a is LF = Line feed .
ASCII-Tabelle
Try using trim() on the value you are testing for. If there is white space you can't see at the end it won't match.
$attributeindex = trim( array_search($index, $attributearray) );