logs archiveIRC Archive / Freenode / #php / 2015 / July / 7 / 1
delboy1978uk
whats the full test string though, can you paste the actual input into the test string?
theskillwithin
I have an array of arrays, and I want to access and overwrite all the [x][1] arrays
foreach ($array as $value)
sorabji
o.0
theskillwithin
$value[$count][1]
$count++;
sorabji
theskillwithin: i'm not following. can you make a paste?
irc is an awful place to type code in
reading it is even worse
delboy1978uk
theskillwithin: it should be $value[1]
$value IS $key[$count]
$array rather not $key
theskillwithin
http://pastebin.com/FrvcMWvY
something like that
sorabji
theskillwithin: the practical result of that code is nothing
delboy1978uk
what are you trying to do?
that code does nothing but loop through
         

theskillwithin
I made a function that will get the SalesRank of the ASIN. I want to delete all the ASINS except the one with the lowest ASIN ranking. leaving me with a upc at 0 and an asin at 1
I think id have to use array map in there too
sorabji
...
this is still not making sense
you have an integer key to an array with two values
which is the rank?
theskillwithin
so in the array [x][1] I have 'B00DILW3IU,B002ZVXFMM,B004UC0S7O,B000MIF29O'
i can run each easin through my function Amazon(B00DILW3IU)
it will return a number, the lowest number wins
matt889
hello, is anyone available to help make sense of a 5.6 core dump? there seems to be a lot missing which is not usually the case. http://pastebin.com/TH69Cc3Q
sorabji
theskillwithin: ahh, so there's some other code that gives you the rank?
theskillwithin
then I delete all the asins in that spot except for the winner
ya
delboy1978uk
theskillwithin: http://codepad.viper-7.com/P7MejV
theskillwithin
so then I would go in and say for $data[312][1] = only the winning asin
sorabji
lowest overall? or lowest within that particular group?
theskillwithin
lowest within that group
iw ould have to explode that group by ,
sorabji
yes, do the explode
delboy1978uk
ive done it already you just need to sort
sorabji
walk the result of that applying your ranking function, sort and pick the winner
did you ever break down and use the api amazon provides?
runinsquares
you want your code to look like getRank($data[321][1])? and it returns the winner?
theskillwithin
hmm but exploding them takes it out of the array?
ahh I would just put it back
sorabji
theskillwithin: actually, you can just use uasort with a custom function that uses your ranking function
theskillwithin
$array[$key][1] = "
winning asin"
sorabji
theskillwithin
I would usort the $ex right after the explode?
runinsquares
in terms of data manipulation it's better to pass in an array rather than a string of crap, unless of course the function's purpose is to spit back a formatted version of that string of crap
         

delboy1978uk
theskillwithin: yes
theskillwithin
then array_values to make it 1 key
then $array[$key][1] = "that asin" to put it back at the end
delboy1978uk
no, just $val[1] = $the_winner;
runinsquares
your array would be better as $data[312][1]['00DILW3IU,B002ZVXFMM,B004UC0S7O,B000MIF29O]; imho
ofc without the formatting mistake
theskillwithin
u mean without the upc?
delboy1978uk
upc?
runinsquares
$data[312][1]['00DILW3IU','B002ZVXFMM','B004UC0S7O','B000MIF29O'];
serve it as array instead of a string
$data[321][1][0] // 00DILW3IU
theskillwithin
oh man
so to do that, i would explode before doing all this
delboy1978uk
he already has it exploded as an array to sort. he just needs to usort it and assign the winning variable to $val[1];
!+usort
php-bot
bool usort(array array_arg, mixed comparator) - Sort an array by values using a user-defined comparison function - http://php.net/usort
theskillwithin
ohh i see cuz the explode makes its own array
delboy1978uk
yup
runinsquares
if you're never gonna need those values again delboy1978uk makes a point
theskillwithin
seperate from my array
but thats ok
cuz i just sort that
and take the winner
delboy1978uk
if you need the other vars, just implode the sorted array by a comma and assign that
runinsquares
if he's gonna do that then imo he should use array, if he is gonna throw the values away after explode, keep it simple. that's imo ofc
delboy1978uk
he cant sort them while they are all one big string, he must explode first
runinsquares
theskillwithin, is there also a chance you will later want to add something to the values in [1]? $data[312][1]['00DILW3IU']['last-use-date'] // random example
theskillwithin
usort ( $ex , array_map(amazon, $ex) )
nah once there sorted and associated with a UPC I will just output to a csv
runinsquares
alright what delboy1978uk is suggesting is aok then
theskillwithin
so I can use array_map as my "value compare fuctnion" ?
delboy1978uk
use usort
whats the actual algorithm that sorts them?
if it was numerical id give you an example
but it aint
theskillwithin
seeing which ASIN of the group has the lowest ranking
and keeping that
delboy1978uk
i dont know what an ASIN is, it that the string value?
theskillwithin
an ASIN is an amazon product code
so I am trying to upload producst to amazon via UPC. If that UPC is attached to more than 1 ASIN it will give error and say pick an ASIN.
delboy1978uk
oh that yeah im sure ive heard of that before actually
how do you get the ranlk?
theskillwithin
rest api request
to amazon
delboy1978uk
right ok so you need to create a function to pass into usort, that grabs that value to compare
look at example 1 on the usort page
$a and $b would be the ASINS
before the if, do the api calls
sorry $a and $b are the asins RANK
theskillwithin
I think im getting close
http://pastebin.com/CHMx8iNv
Pnoexz
hey, quick question. How can I check how many dimensions an array has?
« prev 1 2 3 4 5 6 7 8 9 10 next »