Skip to content
Advertisement

How to dynamically get column value from csv file using php

i have two columns in csv file Name and Phone . If i given phone number as a variable $searchStr = "6059574150"; it has to find number in csv file and i need that contact name to get access dynamicaly like this $data[‘Name’] instead of $data[‘0’] MY php code

JavaScript

my output is like this

JavaScript

how to directly access column ? like this $data[‘Name’]

Advertisement

Answer

If phone numbers are unique, you could do something like this:

JavaScript

If you have more than one name (person) for each phone number, you can concatenate them $final_result[$data[1]] .= ',' . $data[0];.

Example result:

JavaScript

To search a name from a phone number you have to do: $final_result[phone_number] and you get the name.


In your output array “$final_result” you can look for a Name by phone number this way:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement